0

I have data which is loaded via ajax and I would like to disable a click event on li element which has a class active, the below is what I tried. can someone help me out?

$('body').on("click", 'li *:not(.active)', function (e) {
    //do something
}); //this doesn't work
2
  • .click() function is more appropriate. Commented Dec 27, 2014 at 20:30
  • 2
    @JuanRocamonde - .click() won't work with dynamically added content. Commented Dec 27, 2014 at 20:31

3 Answers 3

2

You are targeting all non-active descendants of list items.

  • Remove the universal selector
  • Remove the descendant combinator

Such:

'li:not(.active)'
Sign up to request clarification or add additional context in comments.

Comments

0

If the active class is on the li then remove the space and * (which targets all descendant elements that do not have the active class)

$('body').on("click", 'li:not(.active)', function (e) {
    //do something
}); //this doesn't work

Comments

0

Um, that code is not looking at an li element, thatmselector is looking for a child of an li element. Get rid of the space and * and it will check the li.

li:not(.active)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.