Get the App
SLTechnology News&Howtos  ›  Development  › 

How jQuery uses the is () method

Shulou Source: shulou.com Published: 2022-06-01 04:17:43 09月16日 Update

This article mainly shows you how jQuery uses the is() method. The content is simple and easy to understand. The organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn how jQuery uses the is() method.

is() method

Detects a set of matching elements based on a selector, element, or jQuery object, and returns true if at least one of these elements matches the given parameter. Some small applications are as follows:

list item 1 list item 2 list item 3$("ul").click(function(event) { var $target = $(event.target); if ( $target.is("li") ) { $target.css("background-color", "red"); }});

In this way, you can limit that only after clicking on the list item li itself, the click event written will be triggered.

It can also make the following judgments:

//is it a divelem.is ('div ') && console.log("it's a div");//is it an element with a class name that contains (or can have) a bigbox? elem.is('.bigbox') && console.log("it has the bigbox class! ");//is it hidden? elem.is(':not(:visible)') && console.log("it is hidden! ");

One thing to note here is that the && operator can be used to make a judgment. When the previous condition is satisfied, the latter will be executed, but the latter condition cannot be an expression, only a console.log() or ++i.

There are also the following useful uses:

elem.animate({'width': 200},1000);//elem.is (': animated')& console.log("it is animated!") "); That's all for" How jQuery uses the is() method ". Thank you for reading it! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Elements methods content articles conditions class names learning help events animation parameters only objects few easy to understand more useful organized being knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Docker Shulou Tech Info Redmi