jQuery stop function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziycon
    Contributor
    • Sep 2008
    • 384

    jQuery stop function

    Is there a function to tell jquery to only do something on the first instance that matches then to stop.

    For example I add a class to a LI to an UL with the below but it adds the LI to all ULs under it.
    Code:
    $("div#container ul").prepend("<li>Home</li>");
    Original code:
    Code:
    <ul>
      <li>
        <ul>
          <li>item</li>
        </ul>
      </li>
    </ul>
    Code needed:
    Code:
    <ul>
      <li>Home</li>
      <li>
        <ul>
          <li>item</li>
        </ul>
      </li>
    </ul>
    Currently Output code:
    Code:
    <ul>
      <li>Home</li>
      <li>
        <ul>
          <li>Home</li>
          <li>item</li>
        </ul>
      </li>
    </ul>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You could give the UL a class and use that to select, or use the :first selector.

    Comment

    Working...