JQuery selectors: how to use?

JQuery – , JavaScript, HTML . , , CSS. jQuery .

CSS jQuery

, jQuery CSS, «».

  • -, jQuery , DOM, . . , , hover, - first-line.
  • -, jQuery , CSS, , CSS, .
JQuery library for working with HTML page




, . CSS:

$("*")

$("b")

HTML, - <b>...</b>

$(".classA")

(<div class="classA">)

$("#IDone")

id (<div id="IDone">)

CSS, jQuery . . , jquery ID - $("#IDone, b"). +, +ID, , $("b.classA").





CMS, , HTML- Id . , . , , jquery.

$("div[attribute]"),
$("div[attribute='value']"),
$("div[attribute!='value']"), . ,
$("div[attribute^='value']"), , value
$("div[attribute$='value']"), , value
$("div[attribute*='value']"), value
$("div[attribute~='value']"), value ( )
$("div[attribute|='value']"), value ,
An example of using attribute selectors




, , , $("img[width=500][height=260]").





HTML- - jQuery. , , , jquery , (<p></p>).

:contains()$("p:contains('value')") – <p>, 'value'., . , . , , "text" "TEXT"
:has()$("p:has(b)") – <p>, <b>., , .
:parent$("p:parent") – <p>, -., -
:empty$("p:empty") – <p>., .

.

HTML markup matching selectors




jquery , , $("p.mail:contains('e-mail')") "mail", "e-mail".

CSS. , DOM. jquery .

$("ul > li")<li>, () <ul>
$("ul a")<a>, <ul>
$("h1 + p")<p>, <h1>
$("li ~ a")<a>, <li>, ,
$("li:first-child")<li>, , , <ul>
$("li:last-child")<li>, , , <ul>
$("li:nth-child(3)")<li>, . , ,
$("li:only-child")<li>, ()
Inheritance of elements




jquery li:nth-child(n), . , n even, , odd. n , , $("li:nth-child(2n+3)") , .

input , type. jQuery .

Input Fields




:button$("input:button")
:checkbox$("input:checkbox")
:file$("input:file")
:image$("input:image")

:password$("input:password")
:radio$("input:radio")-
:reset$("input:reset")
:submit$("input:submit")
:text$("input:text")
:input$(":input")
:checked$("input:checked")-
:selected$("option:selected")option
:disabled$("input:disabled")
:enabled$("input:enabled")

JQuery . .

:first
:last
:eq(n)(n). ! , jQuery select 0!
:lt(), n
:gt(), n
:even
:odd
Using selector: gt () to control table styles




- , . , : not(), , "" , .

: hidden, - 00 , , .

:not(),
:animated, jQuery
:hiddendisplay: none, type="hidden", 0px. , . ! visibility, "hidden", jquery select
:visible: hidden
:header

h1, h2, h3, h4, h5 h6

?

- , , , . jQuery JavaScript , . , .

  1. jQuery.
  2. , . , .
  3. , , - .

An example script with jQuery and its selectors:

Using jQuery selectors




Conclusion

Now you know absolutely all selectors from jQuery, in addition, we hope that the examples helped you understand how to build the desired condition from several different selectors.




All Articles