Home  >  Article  >  Web Front-end  >  Summary of several ways to obtain elements in jquery_jquery

Summary of several ways to obtain elements in jquery_jquery

WBOY
WBOYOriginal
2016-05-16 18:05:101285browse

1 Get the element
html from the collection with the specified serial number:

Copy the code The code is as follows:


0


1


2


3


4


5


6


7< /p>



JS
Copy code The code is as follows:



2 Get elements with consistent specified conditions and specified range
html:
Copy code The code is as follows:


0


1


2< /p>

3


4


5


<

7




JS
Copy code The code is as follows:



3 Get elements consistent with the conditional expression
html:
Copy code The code is as follows:


< p>0


1


2


3


4


5


6


7




js
Copy code The code is as follows:



4 Get the previous element and next element of the element
Html:
Copy code The code is as follows:


No. 1

No. 2


No. 3


No. 4


No. 5


No. 6


No. 7< /p>



js
Copy code The code is as follows:

//Get the next element of the element
jQuery(function(){
$("p").next(".yes").css("color", "red");
})
//Get the previous element of the element
jQuery(function(){
$("p").prev(".yes").css( "color","red");
})

5 Get the parent element and child element of the element
html:
Copy code The code is as follows:


No. 1


No. 2


No. 3


No. 4


No. 5


No. 6


No. 7




js
Copy code The code is as follows:

//Get the parent element of the element
jQuery( function(){
$("p").parent().css("color","red");
})
//Get the child elements of the element
jQuery(function (){
$("#aa").children(".yes").css("color","red");
})
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn