The selector property usage instance of the jQuery object

  • 2020-05-09 18:12:04
  • OfStack

This example demonstrates the use of selector properties for jQuery objects. Share with you for your reference. The specific analysis is as follows:

This property returns the original selector passed to jQuery, which selector jQuery used to match the current element.

The selector property can be used in conjunction with context to accurately detect selector queries.

Grammatical structure:

$("selector").selector

Example code:


<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title> The home of the script </title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#btn").click(function(){
    $("div").text(" The original selector is: "+$("ul li").selector);
  })
});
</script>
</head>
<body>
  <div></div>
  <button id="btn"> Click to view an example </button>
</body>
</html>

The above code USES the selector attribute to return which selector $() matches the element with.

I hope this article has helped you with the jQuery programming.


Related articles: