Home  >  Article  >  Web Front-end  >  How to get elements other than yourself in jquery

How to get elements other than yourself in jquery

WBOY
WBOYOriginal
2021-12-13 16:17:003055browse

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)".

How to get elements other than yourself in jquery

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:

How to get elements other than yourself in jquery

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn