Home > Web Front-end > JS Tutorial > body text

How to get elements other than yourself in jquery

WBOY
Release: 2021-12-13 16:17:00
Original
3142 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template