user745943
user745943

Reputation:

Getting DOM by name attribute in dojo javascript framework

How to get a DOM using dojo by the tag name?

I have a html code like this :

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

in jQuery framework, it will be:

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

...but in Dojo framework, what must I do ?

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

Upvotes: 3

Views: 13196

Answers (2)

Daniel Pern&#237;k
Daniel Pern&#237;k

Reputation: 5852

Consider you have an input field named 'myInput'. <input id="1" name="myInput" />

For getting a value (or other attribute) use following: ([0] define index of your component)

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

If you want to set some value, you will do this:

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

Upvotes: 1

Frode
Frode

Reputation: 5710

Yes, dojo.query("select[name=limit]") is 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 select the first element:

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

Upvotes: 8

Related Questions