0

im used to use jquery .index() and need some help to understand how to works Dojo Nodelist. My code:

<ul id="indexof1">
<li><a id="1">domain_1.net</a></li>
<li><a id="2">domain_2.com</a></li>
<li><a id="3">domain_3.org</a></li>
<li><a id="4">domain_4.net</a></li>
</ul>

require(["dojo/query", "dojo/on", "dojo/NodeList-traverse"], function(query, on){
query("ul a").on("click", function(){ 
    console.log(query(this).parent().parent()[0]); // Returns UL
    console.log(query(this)[0]); // Returns the node has been clicked A
    alert(query('a', query(this).parent().parent()[0]).indexOf(query(this)[0]));
});
});

https://jsfiddle.net/wwghes79/4/

David
  • 519
  • 2
  • 11

1 Answers1

0

This should help you with the requirement you have:

 require(["dojo/query", "dojo/on", "dojo/NodeList-traverse"], function(query, on){
        query("ul a").on("click", function(e){ 
         console.log(query("#indexof1 li a").indexOf(this)); //returns index
        });
    });
Tarang
  • 318
  • 1
  • 10