Home > Article > Web Front-end > How to get elements other than yourself in jquery
In jquery, you can use the not() method and this keyword to obtain elements other than yourself. The not() method is used to return elements that do not meet the conditions in the specified element. The this keyword can select the current element. An object, as a qualified element, the syntax is "$("parent element*").not(this)".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How jquery gets elements other than itself
You can use the not() method and this keyword to get elements other than yourself.
not() method returns elements that do not meet certain conditions.
This method lets you specify a condition. Elements that do not meet the criteria will be returned from the selection, and elements that meet the criteria will be removed.
This method is usually used to remove one or more elements from the selected element combination.
The example is as follows:
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(function(){ $("div p").click(function(){ $("div *").not(this).remove(); }); }); </script> </head> <body> <div> <p class="aa">aa</p> <p class="bb">bb</p> <p class="cc">cc</p> </div> </body> </html>
Output result:
Related video tutorial recommendation: jQuery video tutorial
The above is the detailed content of How to get elements other than yourself in jquery. For more information, please follow other related articles on the PHP Chinese website!