Complete parsing of js selectors and comprehensive parsing of selectors
The native JS selectors include getElementById, getElementsByName, getElementsByTagName, and getElementsByClassName. Next I will introduce the usage of these four selectors one by one.
1. getElementById (get the element through ID)
Usage: document. getElementById ("Id"); Id is the id attribute value of the element to be obtained.
2. getElementsByName (get the element through the name attribute)
Usage: document. getElementsByName ("Name"); Name is the name attribute value of the element to be obtained. This method is generally applicable to submitting form data, when the name attribute is set when the elements are form, img, iframe, applet, embed, and object, an attribute named after this name attribute value is automatically created in the Document object. Therefore, you can use document. domName to reference the corresponding dom object.
3. getElementsByTagName (obtain the element through the element name)
Usage: document. getElementsByTagName (TagName); TagName is the Tag Name of the element to be obtained. When TagName is *, all elements are obtained. You can also change the document to a DOM element, however, only the subset elements after the DOM element can be obtained.
4. getElementsByClassName (obtain elements through CSS classes)
Usage:Document. getElementsByClassName (ClassName); ClassName is the name of the CSS class for obtaining elements. If you want to obtain multiple CSS classes at the same time, separate them with spaces after each CSS class. Such as document. getElementsByClassName ("class2 class1") gets the elements of the class1 and class2 styles, and the document can also be changed to the DOM element. In this way, only the subset elements after the DOM element can be obtained.
<! DOCTYPE html> <! DOCTYPE html>
The above is the js selector provided by the mini-editor to fully parse all the content. I hope you can provide more support to the customer's home ~