How to get the value 10. Does it have to be below the script?

How to get the value 10. Does it have to be below the script?
pure JavaScript, please.

<script>
    var ok = document.querySelector('.australianbrothers [name="longliveaustralia"]').value;
    document.write(ok);
</script>
<li class="australianbrothers">
    <input type="hidden" name="longliveaustralia" value="10">
</li>

The web browser works through the code sequentially. When the web browser gets to the script code, it knows nothing about the other HTML tags that are below the script. For that reason, it’s best for scripts to be below everything else.

You can easily achieve that by placing the script just before the </body> tag.

really works Thanks

Though while you’re at it, your query selector can be reduced to [name="longliveaustralia"], because a form field with that name should be unique.

Sorry man, name attributes aren’t required to be unique,

You can have different forms that use the same name attributes. You can even repeat the same name attributes within the same form.

It is Id attributes instead that should be unique,

I’m aware they’re not required to be unique, but if you’re writing code for something as specific as .australianbrother [name="longliveaustralia"], i’m guessing it’s unique.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.