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!

0

1 Answer 1

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) {
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.