JQuery basic Selector
Selector
Description
Return
# Id
Matches an element based on the given id.
Single element
. Class
Matches the element based on the given class name.
Set Element
Element
Match an element based on the given element name
Set Element
*
Match All elements
Set Element
Selector1, selector2 ,...
Returns the elements matched by each selector together.
Set Element
Example:
[Javascript]
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"
Http://www.w3.org/TR/html4/loose.dtd>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> New Web Project </title>
<Script type = "text/javascript" src = "jquery-core/jquery-1.8.0.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ('# Bt1'). click (function (){
Alert ('Id selector: '{}('{d1'}.html ()
+ "\ Nclass selector:" commandid ('.c1'0000.html ()
+ "\ Nelement selector:" commandid ('p'%.eq(0%.html ()
+ "\ N * selector:" + $ ('* '{.eq(5}.html ()
+ "\ N multiple selector selected quantity:" + $ ('div, p, # bt1'). length
);
});
});
</Script>
</Head>
<Body>
<Div id = "d1"> I am a div </div>
<Div class = "c1"> I am a div2 </div>
<P> I am a p </p>
<Input type = "button" value = "button" id = "bt1"/>
</Body>
</Html>