In all examples, an abbreviated version of the jQuery method call is used, using the function $ (dollar sign)
< div id = "header" >
< h1 > <a href = "/" title = "homepage"> Title < / a > < / h1 >
< h2 > Sub-title < span > small description < / span > < / h2 >
< / div >
< div id = "wrapper" >
< div id = "content" >
< div class = "post" >
< h3 > Post Title < / h3 >
< p > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed viverra tempus sapien.
Cras condimentum, tellus id lacinia fermentum, tortor lectus tincidunt sapien,
vel varius augue tortor vel tortor. < / p >
< span > Image Title < / span >
< img src = "/image1.jpg" alt = "Image Alt Text" / >
< p > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed viverra tempus sapien.
Cras condimentum, tellus id lacinia fermentum, tortor lectus tincidunt sapien,
vel varius augue tortor vel tortor. < / p >
< span class = "inner-banner" > Banner Text < / span >
< p > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed viverra tempus sapien.
Cras condimentum, tellus id lacinia fermentum, tortor lectus tincidunt sapien,
vel varius augue tortor vel tortor. < / p >
< / div >
< span id = "banner" > < img src = "/banner1.jpg" alt = "Big Banner" / > < / span >
< div class = "post" >
< h3 > Post Title < / h3 >
< p > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed viverra tempus sapien.
Cras condimentum, tellus id lacinia fermentum, tortor lectus tincidunt sapien,
vel varius augue tortor vel tortor. < / p >
< span > Image Title < / span >
< img src = "/image2.jpg" alt = "Image Alt Text" / >
< p > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed viverra tempus sapien.
Cras condimentum, tellus id lacinia fermentum, tortor lectus tincidunt sapien,
vel varius augue tortor vel tortor. < / p >
< span class = "inner-banner" > Banner Text < / span >
< p > Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed viverra tempus sapien.
Cras condimentum, tellus id lacinia fermentum, tortor lectus tincidunt sapien,
vel varius augue tortor vel tortor. < / p >
< / div >
< / div >
< / div >
< div id = "sidebar" >
< ul >
< li > <a href = "/item0.html"> Menu Item 0 < / a > < / li >
< li > <a href = "/item1.html"> Menu Item 1 < / a > < / li >
< li > <a href = "/item2.html"> Menu Item 2 < / a > < / li >
< li > <a href = "/item3.html"> Menu Item 3 < / a > < / li >
< / ul >
< / div >
< div id = "footer" >
Copyright & copy; 2008
< / div >
$ ( '#sidebar' ) ; // select element with id = sidebar
$ ( '.post' ) ; // select items with class = post
$ ( 'div # sidebar' ) ; // select div element with id = sidebar
$ ( 'div.post' ) ; // select div elements with class = post
$ ( 'div span' ) ; // select all span elements in div elements
$ ( 'div' ) . find ( 'span' ) ; // select all span elements in div elements
$ ( 'div> span' ) ; // select all span elements in div elements, where span is a direct descendant of the div
$ ( 'div, span' ) ; // select all div and span elements
$ ( 'span + img' ) ; // select all img elements before which the span elements go
$ ( 'span ~ img' ) ; // select all img elements after the first span element
$ ( '#banner' ) . prev ( ) ; // select the previous item from the found
$ ( '#banner' ) . next ( ) ; // select the next item from the found one
$ ( '*' ) ; // select all items
$ ( 'p> *' ) ; // select all descendants of p elements
$ ( 'p' ) . children ( ) ; // -
$ ( 'p' ) . parent ( ) ; // select all direct ancestors of p elements
$ ( '*> p' ) ; // select all ancestors of p elements (most likely you will not need it)
$ ( 'p' ) . parents ( ) ; // -
$ ( 'p' ) . parents ( 'div' ) ; // select all the ancestors of the p element which is a div (parents takes as a parameter a selector)
$ ( 'div: first' ) ; // choose the first div in the house
$ ( 'div: last' ) ; // choose the last div in the house
$ ( 'div: not (.red)' ) ; // choose divs that don't have red class
$ ( 'div: even' ) ; // select even divs
$ ( 'div: odd' ) ; // choose odd divs
$ ( 'div: eq (N)' ) ; // choose a div going with the number N in the DOMe
$ ( 'div: gt (N)' ) ; // choose divs whose index is greater than N in DOMe
$ ( 'div: lt (N)' ) ; // select divs whose index is less than N in DOMe
$ ( ': header' ) ; // select the headers h1, h2, h3, etc.
$ ( 'div: animated' ) ; // select elements with active animation
$ ( 'div: contains (text)' ) ; // select the divs containing the text
$ ( 'div: empty' ) ; // select empty divs
$ ( 'div: has (p)' ) ; // select the divs that contain p
$ ( 'div.red' ) . filter ( '.bold' ) // select divs that contain the red class and the bold class
$ ( 'div: hidden' ) ; // select hidden divs
$ ( 'div: visible' ) ; // select visible divs
$ ( "div [id]" ) ; // select all divs with id attribute
$ ( "div [title = 'my']" ) ; // select all divs with title = my attribute
$ ( "div [title! = 'my']" ) ; // select all divs with title attribute not equal to my
$ ( "div [title ^ = 'my']" ) ; // select all divs with title attribute starting with my
// <div title = "myCat">, <div title = "myCoffee">, <div title = "my ...">
$ ( "div [title $ = 'my']" ) ; // select all divs with title attribute ending with my
// <div title = "itsmy">, <div title = "somy">, <div title = "... my">
$ ( "div [title * = 'my']" ) ; // select all divs with title attribute containing my
// <div title = "itsmy">, <div title = "myCat">, <div title = "its my cat">, <div title = "... my ...">
$ ( "a [rel ~ = 'external']" ) ; // select all A with the rel attribute containing external in the list of values separated by a space
<a href = "" rel = "external"> link < / a > - yes
<a href = "" rel = "nofollow external"> link < / a > - yes
<a href = "" rel = "external nofollow"> link < / a > - yes
<a href = "" rel = "friend external follow"> link < / a > - yes
<a href = "" rel = "external-link"> link < / a > - no
$ ( ": text" ) ; // select all input elements with type = text
$ ( ": radio" ) ; // select all input elements with type = radio
// and so on
$ ( "input: enabled" ) ; // select all included input elements
$ ( "input: checked" ) ; // select all checked checkboxes
$ ( "div [name = city]: visible: has (p)" ) ; // select a visible div called city which contains the p tag
$ ( "form select [name = city] option: selected" ) . val ( ) ; // get the selected (s) elements in the city
$ ( "form: radio [name = some]: checked" ) . val ( ) ; // get the selected radiobath value some
$ ( "form: checkbox: checked" ) ; // select all selected checkboxes
Source: https://habr.com/ru/post/51717/
All Articles