亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery syntax

jQuery syntax

jQuery syntax is to select HTML elements and perform certain operations on the selected elements.

Basic syntax: $(selector).action()

Dollar sign definition jQuery

Selector (selector) "query" and "find" HTML elements

jQuery's action() performs operations on elements

Example:

$(this).hide() - Hide the current element

$("p").hide() - Hide all <p> elements

$("p.test").hide() - Hide all classes <p> elements with ="test"

$("#test").hide() - Hide all elements with id="test"

Document ready event

You may have noticed that all jQuery functions in our example are located in a document ready function:

$(document).ready(function( ){
// Start writing jQuery code...
});

This is to prevent jQuery code from running before the document is fully loaded (ready).

If you run the function before the document is fully loaded, the operation may fail. Here are two specific examples:

Trying to hide a non-existent element

Getting the size of an incompletely loaded image

Tip: Concise writing (same effect as above) Same):

$(function(){

// Start writing jQuery code...

});

You can choose the method you like to execute the jQuery method after the document is ready.


Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").empty(); }); }); </script> </head> <body> <div id="div1" style="height:100px;width:300px;border:1px solid black;background-color:green;"> <p>這是一段內(nèi)容</p> <p>這還是一段內(nèi)容</p> </div> <br> <button>清空框里內(nèi)容</button> </body> </html>
submitReset Code