jquery - Appending link element within list element dynamically -


with using jquery need create element added inside <li> has own content. final result should below

<li> hello <a> user! </a> welcome! </li> 

so far have tried out below.

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

but give output below.

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

how can include 'hello' , 'welcome' on either side of <a> ?

you can this.

console.log(    $('<li/>', {      html: [        document.createtextnode(' hello'),        $('<a> user! </a>'),        document.createtextnode('welcome! ')      ]    })[0].outerhtml  )
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -