user2894296 user2894296 - 1 year ago 64
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

Answer Source

You can do something like this.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download