Home >Web Front-end >JS Tutorial >jQuery Learning 2 Selector Instructions_jquery

jQuery Learning 2 Selector Instructions_jquery

WBOY
WBOYOriginal
2016-05-16 18:35:231211browse
1. Use basic CSS selectors:
a: Match all link elements.
#*: Matches elements with id *
.*: Matches elements with CSS class *
a#*id.*class: Matches links with id *id and has CSS class *class element.
The above is how it is written in CSS, wrapped in $("") in jQuery, such as: jQuery("p a.Class")

Use sub-selectors, container selectors and attribute selection Take the following as an example:
Copy code The code is as follows:



If you want to select all the links in the first list
  • , you should use the sub-selector: ul.myList > ; li >a and not like this ul.myList li a because all these links are descendant nodes of list
  • elements.
    Child selector: parent node and direct child node are pointed to the right separated by brackets (>).
    Attribute selector: Wrap elements that match specific content. For example, select a link containing an href value starting with http://: a[href^=http://]
    input[type=text]: Match all elements
    whose type attribute is text div[title=^my]: Matches all