jQuery > Attribute related method

.prepend() - Insert content at beginning in jQuery

How to insert html content at the beginning of an element in jQuery?


To insert html content at the beginning of an element, prepend() method can be used

<script>
      $("#div2").prepend("Prepending text : ");
  </script>

Above code snippet will insert specified string at the beginning of the element “div2” element.

For example, below code

<div id="div2" class="class1">Demo of <b>attr</b> attribute</div>

Will change to

<div id="div2" class="class1">Prepending Text : Demo of <b>attr</b> attribute</div>

After executing the above prepend statement (notice the bold text).

 Views: 4865 | Post Order: 32



Write for us






Hosting Recommendations