问题描述:

I'm trying to add following html code into a div called by its id name #nitspopupmenu :

<div class="form-group">

<div class="pagesmenu">

<span>

<i class="fa fa-bars"></i> Home

</span>

</div>

</div>

I tried to append the above html tags but that didn't worked then I tried wrapinner but confused with the documentation of wrapinner as it says we can insert <span> tags but I'm getting an error of illegal token.

My Jquery looks like:

var element = $("li").text();

$("#nitspopupmenu").wrapInner(function () {

return "<div class='form-group'><div class = 'pagesmenu selected'><span><i class = 'fa fa-bars'></i>' + element + '</span></div></div>"

});

I'm getting the value of element in my console.log its working fine as desired.

Please help,

Thanks.

网友答案:

You can simply use .html() to set new html or .append() to append the content.

Also make sure that you are concatenating element text correctly while concatenating it with string html:

 var element = $("li").text();
 $("#nitspopupmenu").html("<div class='form-group'><div class = 'pagesmenu selected'><span><i class = 'fa fa-bars'></i>" + element + "</span></div></div>" });
网友答案:

Just add:

var element = $("li").text();

$("#nitspopupmenu").hmtl('<div class="form-group"><div class="pagesmenu"><span><i class="fa fa-bars"></i>'+element+'</span> </div></div>');
相关阅读:
Top