jquery append to front/top of list

Jquery

Jquery Problem Overview


I have this unordered list

<ul>
   <li>two</li>
   <li>three</li>
</ul>

Is there a way I can prepend to the unordered list so that it ends up like this?

<ul>
   <li>ONE</li>
   <li>two</li>
   <li>three</li>
</ul>

Notice the "ONE" is added to the FRONT/TOP of the list.

Jquery Solutions


Solution 1 - Jquery

$("ul").prepend("<li>ONE</li>");

Solution 2 - Jquery

Something simple like this ought to work:

$("ul").prepend("<li>ONE</li>");

Solution 3 - Jquery

use prepend instread of append

<h2>Greetings</h2>    
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>

$('.container').prepend('<p>Test</p>');

refer http://api.jquery.com/prepend/ for more info.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncodingforfunView Question on Stackoverflow
Solution 1 - JquerydasonyView Answer on Stackoverflow
Solution 2 - JquerynezroyView Answer on Stackoverflow
Solution 3 - JqueryIshan LiyanageView Answer on Stackoverflow