Write a program
Create an html page, introduce the jQuery class library and write the following code:
<!doctype html> <html lang="zh"> <head> <meta charset="utf-8"/> <title>Hello World jQuery!</title> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> </head> <body> <div id="divMsg">Hello jQuery!</div> <input id="btnShow" type="button" value="show" /> <input id="btnHide" type="button" value="hidden" /><br/> <input id="btnChange" type="button" value="change content is Hello World, too!"/> <script> $("#btnShow").bind("click", function(event) { $("#divMsg").show(); }); $("#btnHide").bind("click", function(event) { $("#divMsg").hide(); }); $("#btnChange").bind("click", function(event) { $("#divMsg").html("Hello World, too!"); }); </script> </body> </html>
The effect is as follows:
There are three buttons on the page, which respectively control the display, hiding and modifying the content of Hello World.
This example uses:
(1) jQuery ID selector: $("#btnShow") (2) Event binding function: bind() (3) Show and hide Functions: show() and hide() (4) Function to modify the html inside the element: html()
Next Section