Several selectors in JQuery search for elements that meet the conditions $ (& quot; # Control ID & quot ;)

Source: Internet
Author: User

Style: $ (function (){
$ ("Tag to be selected"). click (function () {alert ("pop-up dialog box content ");})
});
First: Id Selector
Usage:
Copy codeThe Code is as follows:
<Head>
<Title> </title>
<Script src = "Jq/jquery-1.4.2.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("P"). click (function () {alert ("Small P ");})
});
</Script>
</Head>

<Body>
<Input type = "button" value = "PlayGame" id = "btnClick"/>
<P> first </p>
<P> second </p>
</Body>

Note: A dialog box is displayed for all <P> tag clicks.
Type 2: CSS Selector
Copy codeThe Code is as follows:
<Head>
<Title> </title>
<Script src = "Jq/jquery-1.4.2.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ (". Warning"). click (function () {alert ("this is a warning message ");});
});
</Script>
<Style type = "text/css">
. Warning {background-color: Yellow; color: Red ;}
</Style>
</Head>

<Body>
<P> no warning </p>
<Div class = "warning"> Please bring your child </div>
<P class = "warning"> warn you again </p>
<Input class = "warning" type = "button" value = "don't click"/>
</Body>

Note: A dialog box is displayed when you click. warning for all CSS styles.
Third: Multi-condition Selector
Copy codeThe Code is as follows:
<Head>
<Title> </title>
<Script src = "Jq/jquery-1.4.2.js"> </script>
<Script type = "text/javascript">
$ (Function (){
$ (". Docc, p, # txt1"). click (function () {alert ("don't be fooled ");})
})
</Script>
<Style type = "text/css">
. Docc {background-color: Fuchsia; color: Olive ;}
</Style>
</Head>

<Body>
<P> selling computers </p>
<Input type = "text" id = "txt1"/>
<Input class = "docc" type = "button" value = ""/>
<Input type = "checkbox"/>
</Body>

Note: You can process multiple selected items at the same time.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.