Tuesday, October 28, 2014

Jquery Prev and Next selector

.prev() and .next() both are Traversing Method . “.prev” Method Returns the previous sibling element of the selected element and
  “next()”Returns the next sibling element of the selected element
.Prev example
<ul>
  <li>list item 1</li>
  <li id=”item2">list item 2</li>
  <li id=”item3">list item 3</li>
  <li>list item 4</li>
  <li>list item 5</li>
</ul>

$("li#item3" ).prev().css( "background-color", "red" );
In this example output second li background –color goes to red

.next() example

P
<ul>
  <li>list item 1</li>
  <li id=”item2">list item 2</li>
  <li id=”item3">list item 3</li>
  <li id=”item4">list item 4</li>
  <li>list item 5</li>
</ul>

$("li#item3" ).next().css( "background-color", "red" );
In this example output fourth li background –color goes to red






No comments:

Post a Comment

http://blogsiteslist.com