Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]") ?


2 Answers

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];
like image 134
Frode Avatar answered Feb 25 '26 08:02

Frode


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';
like image 44
Daniel Perník Avatar answered Feb 25 '26 08:02

Daniel Perník



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!