JavaScript finds HTML nodes, and common jquery selectors

Source: Internet
Author: User
Tags tag name

  The document interface provides methods for locating nodes, all of which look for nodes throughout an HTML document.

(1) document.getElementById ("id");

Get an HTML element object by ID, and the ID number should be unique within the HTML document. Returns a unique element object. And all browsers are compatible.

(2) document.getElementsByTagName ("TagName");

To find an HTML object through a label, an array is returned. You can position the object of an element based on where the label appears. All browsers are compatible.

(3) Document.getelementsbyname ("name");

Using the Name property to locate the HTML object, this method returns an array, and we can also position the name based on the name in the HTML. IE series is not compatible.

  the jquery selector is divided into basic selectors, hierarchical selectors, filter selectors, and form selectors.

1. The basic selector is the most commonly used selector in jquery and the simplest selector, which finds DOM elements by element ID, class, and tag name.

(1) $ ("#test") select an element with ID test

(2) $ (". Test") Select all elements of class test

(3) $ ("P") Select all <p> elements

(4) $ ("*") Select all elements

(5) $ (". Intro.demo") All class= "Intro" and Class= "demo" Elements

2. The hierarchy selector obtains specific elements through a hierarchical relationship between DOM elements.

(1) $ ("div span") pick <div> all <span> elements inside. (descendant elements, including child elements of child elements ... )

(2) $ ("div > span") Select all child elements under the <div> element name that are <span>.

3 Filter filter rules are the same as the pseudo-class selector syntax in CSS.

(1) $ ("[href= ' # ']") all href attribute values equal to "#" elements

(2) $ ("[href$= '. jpg ']") all href attribute values contain elements that end with ". jpg"

4. Form Selector

(1) $ (": Input") Select all <input>, <textarea>, <select>, <button> elements.

(2) $ (": checkbox") all the <input> elements of the type= "checkbox"

(3) $ (": Radio") <input> Elements of all type= "Radio"

JavaScript finds HTML nodes, and common jquery selectors

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.