Home >Web Front-end >JS Tutorial >How to get parent elements, sibling elements, and child elements using jquery selector_jquery

How to get parent elements, sibling elements, and child elements using jquery selector_jquery

WBOY
WBOYOriginal
2016-05-16 16:48:211618browse

1. Get the parent element

1. parent([expr]):

Get all parent elements of the specified element

Copy the code The code is as follows:

href_fir< /a>
href_sec
href_thr< ;/div>

href_fiv

$(document).ready(function(){
$("a").parent().addClass('a_par');
});

firebug view jquery parent effect

2. Get sibling elements:

1. next([expr]):
Get the next sibling element of the specified element (note that it is the next sibling Element)
Copy code The code is as follows:









  • list item 1

  • list item 2

  • list item 3

  • list item 4

  • list item 5