Home > Article > Web Front-end > How to determine whether objects are the same in jquery
In jquery, you can use the is() method to determine whether the objects are the same. This method can check whether the selected element object matches the selector or jQuery object; the syntax is "jQuery object 1.is(jQuery object 2 )", returns true if the two objects are the same.
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, you can use the is() method to determine whether the objects are the same.
Judge whether two jQuery objects are the same
Use the is()
method provided by jQuery. Note that you cannot directly Use ===
to judge, even if it is the same element, it is false
, because two jQuery objects
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { /* 判断元素是否相同, 使用 is() 方法 不能直接 === 判断, 其实不是同一份 jquery 对象 */ let container1 = $('.container') let container2 = $('.container') // false console.log(container1 === container2); // true console.log(container1.is(container2)); }); </script> </head> <body> <div class="container">hello</div> </body> </html>
# are constructed ##Description:
is() 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 parameters. Syntax:$(selector).is(filter)
Description | |
---|---|
filter | String value containing the selector expression that matches the element.
jQuery video tutorial, web front-end】
The above is the detailed content of How to determine whether objects are the same in jquery. For more information, please follow other related articles on the PHP Chinese website!