jQuery element selector method instance

  • 2020-05-07 19:16:03
  • OfStack

This article illustrates the use of the jQuery element selector. Share with you for your reference. Specific analysis is as follows:

The element selector matches all elements by their names.
Example code:

$("div")

The above code matches all the div elements.
Example code:


<!DOCTYPE html>  
<html>  
<head>  
<meta charset=" utf-8">  
<meta name="author" content="//www.ofstack.com/" />
<title> Element selector - The home of the script </title>
<style type="text/css">
div{
  height:150px;
  width:150px;
  background-color:green;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("div").hide();
  })
})
</script>
</head>
<body>
<div></div>
<button> Click on the hidden div The element </button>
</body>
</html>

In the above code, the div element can be hidden when the button is clicked.

I hope this article is helpful for you to design jquery program.


Related articles: