How to use CSS class names and IDs to get elements in jquery

Source: Internet
Author: User
Tags tag name

In jquery, you can easily use CSS class names and IDs to get elements.

For example:

1 ID: #id

$ (' #ida ')-selects all elements with an ID of IDA, regardless of the tag name of the element.

$ (' Div#ida ')-Select all div tag elements with id Ida.

2 Class:.classname

$ ('. ClassA ')-Select the class name to have a classA of all elements, regardless of their label name.

$ (' Div.classa ')-Select the class name that has a classA for all DIV elements.

The complete example is as follows:

<HTML>
<head>
<title>jquery Get element with class name and id</title>
<scripttype= "Text/javascript" src= "jquery-1.3.2.min.js" ></script>
</Head>
<scripttype= "Text/javascript" >
$ (document). Ready (function () {
var $element = $ ('. Classabc '). html ();
alert ($element);
var $element = $ (' #idABC '). html ();
alert ($element);
});
</Script>
<body>
<H1>jquery Get element with class name and id</H1>
<divclass= "classabc" >
</Div>
<divid= "IdABC" >
This was belong to ' div id= ' IdABC '
</Div>
</Body>
</HTML>
Effect Figure 1:
Click OK after the effect:
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.