jQuery prepend() MethodThe prepend() method inserts specified content at the beginning of the selected elements. Tip: To insert content at the end of the selected elements, use the append() method.
jQuery insertBefore() Method The insertBefore() method inserts HTML elements before the selected elements. Tip: To insert HTML elements after the selected elements, use the insertAfter() method.
prepend() .append() puts data inside an element at the last index; while. . prepend() puts the prepending element at the first index.
1) Using the prepend() method to prepend an element example First, select the ul element by its id by using the querySelector() method. Second, declare an array of strings. Third, for each element in an array, create a new li element with the textContent is assigned to the array element.
$("ul").prepend("<li>ONE</li>");
Something simple like this ought to work:
$("ul").prepend("<li>ONE</li>");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With