Introduction to jQuery basic grammar examples

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

This article illustrates the basic syntax of jQuery with an example. Share with you for your reference. The specific analysis is as follows:

This rule has two parts: getting an jQuery object and doing something on an jQuery object.

$(selector).action()

The following is a detailed explanation of the above grammar rules:
1.$defines jQuery to convert the selected DOM object into jQuery object.
2.selector is a selector, similar to CSS.
3.action() is an operation on the jQuery object.
Note: $is short for jQuery. Such as:
$("div")

We could have written it the following way, but we're used to writing it the same way.

jQuery("div")

Example code:


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title> 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 to hide the box above </button>
</body>
</html>

In the above code, click the button to hide div.

I hope this article has been helpful to your jquery programming.


Related articles: