jquery selecter

Asked 2 years ago, Updated 2 years ago, 42 views

<div id="a">
    <div id="b"></div>
    <div id="c"></div>
</div>

When we say that exists, we want to choose the rest except for the sub-elements of a and a elements.

$("#a, #a *").on("click", function(){

});

Is there a way to not only the selector part here?

jquery

2022-09-21 16:36

1 Answers

not() method. DEMO

// Select all under the reference container object, then select → only those that do not correspond to '#a' or '#a *'.
$('#container *').not("#a, #a *").on('click', function(ev) {
  alert(ev.target.innerText);
});


2022-09-21 16:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.