当前位置: 动力学知识库 > 问答 > 编程问答 >

How to use append or wrapinner div which has span tags in jquery

问题描述:

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>');
分享给朋友:
您可能感兴趣的文章:
随机阅读: