<...">

Getting DOM attribute by name in dojo javascript framework

How to get DOM using dojo by tag name?

I have html code:

<select name="limit">
    <option value="10">10</option>
    <option value="25">25</option>
</select>

in the jQuery framework, this will be:

var limit = $("select[name=limit]");

... but within the dojo framework, what should I do?

Should i use dojo.query("select[name=limit]")?

+3
source share
2 answers

Yes, dojo.query("select[name=limit]")correct, but remember that in dojo it returns an array (even if there is only one match in the DOM). So, to get the first (and possibly only) match, you need to select the first element:

var limit = dojo.query("select[name=limit]")[0];
+8
source

You have an input field called myInput. <input id="1" name="myInput" />

To get a value (or other attribute) use the following: ([0] determine the index of your component)

dojo.query('[name="myInput"]').attr('value')[0];

If you want to set some value, you will do the following:

dojo.query('[name="myInput"]')[0].value = 'newValue';
+1
source

All Articles