1.

What Is .siblings() Method In Jquery?

Answer»

<UL>

  • When we WANT to fetch siblings of EVERY elements in the set of matched elements then we can use siblings() method.
  • We filter the elements fetched by an optional selector. • Syntax : .siblings( [selector])
  • “selector” is the selector expression which specify the matched elements.
  • For example

     &LT;ul> 

    <li>item 1</li>

    <li id="&rdquo;second_item&rdquo;">item 2</li>

    <li CLASS="&rdquo;myitem&rdquo;">item 3</li>

    <li class="&rdquo;myitem&rdquo;">item 4</li>

    </ul>

    Now we want to find the siblings of the element of id “second_item” and change the text color to Blue :

    $(‘li.second_item’).siblings().css(‘color’,’blue’);

    If we want specific sibling elements for example the elements having class “myitem” then we can pass a optional selector:

    $(‘li.second_item’).siblings(‘.myitem’).css(‘color’,’blue’);

    For example

     <ul> 

    <li>item 1</li>

    <li id="&rdquo;second_item&rdquo;">item 2</li>

    <li class="&rdquo;myitem&rdquo;">item 3</li>

    <li class="&rdquo;myitem&rdquo;">item 4</li>

    </ul>

    Now we want to find the siblings of the element of id “second_item” and change the text color to Blue :

    $(‘li.second_item’).siblings().css(‘color’,’blue’);

    If we want specific sibling elements for example the elements having class “myitem” then we can pass a optional selector:

    $(‘li.second_item’).siblings(‘.myitem’).css(‘color’,’blue’);



    Discussion

    No Comment Found