Learn the core functions of jQuery today.
jQuery(expression,[context])
This function takes a string containing a CSS selector and uses this string to match a set of elements.
The core functions of jQuery are implemented through this function. Everything in jQuery is based on this function, or uses this function in some way. The most basic use of this function is to pass it an expression (usually composed of a CSS selector) and then find all matching elements based on this expression.
By default, if the context parameter is not specified, $() will search for DOM elements in the current HTML document; if the context parameter is specified, such as a DOM element set or a jQuery object, it will search in this context. (Excerpted from jQuery API)
Without further ado, let’s just look at the examples:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns=" http ://www.w3.org/1999/xhtml"><head><title>Hello World jQuery</title><style>.showtext{ background:#999999; color:#990000; font-weight:800; width :auto; height:40px;}.showtext3{ background:#666; color:#0000FF; font-weight:600; width:auto; height:30px;}</style><script type="text/javascript" src ="jquery-1.3.2-vsdoc2.js"></script></head><body><div id="divMsg" style="color:#FF0000; font-size:18px; font-family:'新宋体'">Unintentional testing of JQuery!</div><input id="btnShow" type="button" value="Show" /> <input id="btnHide" type="button" value="Hide" / ><br /> <input id="btnChange" type="button" value="Modify the content to Hello World jQuery!" /> <input id="btnChange2" type="button" value="Modify the content to unintentional testing JQuery!!" /> <script type="text/javascript">$("#btnShow").bind("click",function(event){$("#divMsg").show("fast")} ); $("#btnHide").bind("click",function(event){$("#divMsg").hide("slow")}); $("#btnChange").bind("click ", function(event) { $("#divMsg").html("Hello World jQuery!"); }); $("#btnChange2").bind("click",function(event){$(" #divMsg").html("Unintentionally testing JQuery!!");});</script> <h4>By the way, let me introduce my QQ senior group 67221760 (stock trading group)! </h4> <div><p>I’m late for work today! </p></div><div></div><div><p>But you have to blog on time</p></div><div><p>It doesn’t matter if you deduct your salary</p> </div><span>9999999999999999999</span><span class="showtext2">3333333333333333333</span><script language="javascript">$( function() { //Match all span elements, var showText= $("span"); //Add the class attribute to all span elements showText.addClass("showtext"); //Match all elements containing p in the div var selectDiv=$("div p"); //showtext's Content assignment showText.text("What can I do if the No. 93 bus doesn't come"); //Add the class attribute to the selectdiv element selectDiv.addClass("showtext3"); //Select elements through CSS class names var selectByClass=$ (".showtext2"); selectByClass.text("Let me first state that I got up very early."); })</script></body></html>