user2894296 user2894296 - 6 months ago 32
HTML Question

Appending link element within list element dynamically

With using jquery I need to create a element to be added inside a

which has its own content. Final result should be like below

<li> Hello <a> user! </a> Welcome! </li>

So far I have tried out below.

var list = $('<li></li>');
var link = $('<a></a>');
link.innerHTML = "user!";

But this will give an output like below.

<li> <a> user! </a> </li>

How can I include 'hello' and 'welcome' on the either side of


You can do something like this.

  $('<li/>', {
    html: [
      document.createTextNode(' Hello'),
      $('<a> user! </a>'),
      document.createTextNode('Welcome! ')
<script src=""></script>