如何使用jquery在span中的文本后添加一些文本?

时间:2022-12-18 20:26:30

I want to insert some text after the text in the span as follows. I want add the &times after Tag1 like "Tag 1 &times". But it the &times is after the </span>, which means outside the span. Thanks.

我想在span中的文本后插入一些文本,如下所示。我想在Tag1之后添加×,如“Tag 1×”。但它的时间是在 之后,这意味着在跨度之外。谢谢。

BTY, is there any good suggestion for the delete button for the tags?

BTY,对于标签的删除按钮有什么好的建议吗?

html:

<li><span>Tag 1</span></li>

jquery:

$('li span').append('<p>&times</p>');

2 个解决方案

#1


5  

var span = $('li span');
span.html(span.html() + '&times');

Is this what you're looking for?

这是你在找什么?

If you want to do it in one line:

如果你想在一行中做到这一点:

$(that).find('span')[0].innerHTML += '&times';

#2


0  

$('li span').after('&times');

#1


5  

var span = $('li span');
span.html(span.html() + '&times');

Is this what you're looking for?

这是你在找什么?

If you want to do it in one line:

如果你想在一行中做到这一点:

$(that).find('span')[0].innerHTML += '&times';

#2


0  

$('li span').after('&times');