jQuery selectors What Birds

jQuery element selectors and attribute selectors allow you to attribute name or the content of HTML elements selected by the tag name.
Selector allows you to set an HTML element or elements when operated.
In HTML DOM terms:
Selector allows you DOM elements DOM node group or individual operation.

jQuery element selector
jQuery CSS selectors to select using HTML elements.
$ ( "P") selected

element.
$ ( "P.intro") select all class = "intro" of

element.
$ ( "P # demo") selects all id = "demo" of

element.

Query attribute selector
jQuery XPath expression to select elements with a given attribute.
$ ( "[href]") select all elements with an href attribute.
$ ( "[href = '# ']") select all values with equal href "#" element.
$ ( "[href! = ' #']") select all elements with href value is not equal to the "#".
( " [ h r e f ("[href = '. JPG']") to select ".jpg" href all elements ending values.

selecting the jQuery CSS CSS properties can be used to change the HTML element.
The following example to change the background color of all p elements in red:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("p").css("background-color","red");
  });
});
</script>
</head>

<body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button type="button">Click me</button>
</body>
</html>

More choices instance
Syntax Description
$ (this) of the current HTML element
$ ( "p") All

Elements
$ ( "p.intro") All class = "intro" of

Elements
$ ( "intro.") All class = "intro" element
$ ( "# intro") id = "intro" element
$ ( "ul li: first" ) each

    First
  • element
    ( " [ h r e f ("[href = '. JPG']") to all href attribute with the ".jpg" end of the attribute value
    $ ( "div # intro .head"the
    All elements class = "head" element

Published 74 original articles · won praise 27 · views 9511

Guess you like

Origin blog.csdn.net/qq_42526440/article/details/102014078
Recommended