1

I have a function which handles a click function for an element:

proot.find("li.ls-child-true").children('div').click(function (e) {
});

My problem is I would like to handle click function on a div child element.

The div looks like this:

<div><a>not clickable</a><a>clickable</a></div>

So, I would like to handle the second anchor click function only, I tried to use this code, but it's not working:

proot.find("li.ls-child-true").children('div').children('a')[1].click(function (e) {
});

Can anybody help to me? Thanks in advance!

user1692315
  • 129
  • 3
  • 10

1 Answers1

3

Use .eq()/:eq() instead of [1], Note [] will return reference to DOM element which don't have access to jQuery methods

proot.find("li.ls-child-true").children('div').children('a').eq(1).click(function (e) {
});

You can improve your selectors

proot.find("li.ls-child-true > div >a:eq(1)").click(function (e) {
});
Satpal
  • 132,252
  • 13
  • 159
  • 168