Any operation of the page requires the support of the node, and the developer can quickly and efficiently find the specified node is also a focus in front-end development. jquery provides a range of selectors to help developers achieve this goal, allowing developers to deal with complex selection processes and performance optimizations less, and more focused on the writing of business logic.
jquery almost supports the writing of mainstream CSS1~CSS3 selectors, and we start with the simplest and most commonly used ones.
ID selector: An ID to find, that is, the id attribute of the element.
$ (' #id ')
The ID selector is also the basic selector, and jquery uses the JavaScript function document.getElementById () to handle the acquisition of the ID. Native syntax support is always very efficient, so altogether consider using this selector if you can use the ID if you are able to manipulate the DOM.
It is worth noting that:
IDs are unique, and each ID value can be used only once in a page. If more than one element is assigned the same ID, only the first DOM element of the selected collection will match the ID. But this behavior should not occur, there are more than one element of the page using the same ID is invalid.
The ID selector of the jquery selector