Jquery 如何在exist div中添加HTML元素,但覆盖内容?
例如,我喜欢:Jquery 如何在exist div中添加HTML元素,但覆盖内容?,jquery,html,Jquery,Html,例如,我喜欢: <div class='title-post'>The content</div> 内容 现在,我想使用Jquery添加元素以获得如下结果: <div class='title-post'><span>The content</span></div> 内容 这意味着我添加了覆盖内容 如何使用Jquery来实现这一点 感谢您的帮助。jQuery的一行: $('.title-post').html($('
<div class='title-post'>The content</div>
内容
现在,我想使用Jquery添加元素以获得如下结果:
<div class='title-post'><span>The content</span></div>
内容
这意味着我添加了
覆盖内容
如何使用Jquery来实现这一点
感谢您的帮助。jQuery的一行:
$('.title-post').html($('<span />').text($('.title-post').text()));
$('.title post').html($('.text($('.title post').text());
小提琴:jQuery的一行:
$('.title-post').html($('<span />').text($('.title-post').text()));
$('.title post').html($('.text($('.title post').text());
Fiddle:使用JQuery API
wrapInner
:
演示
代码
$('.title-post').wrapInner('<span>');
$('.title post').wrapInner('');
使用JQuery APIwrapInner
:
演示
代码
$('.title-post').wrapInner('<span>');
$('.title post').wrapInner('');
downvoter评论?我身体不好,需要帮助。你有什么意见?我不好,所以我需要帮助。不用担心@happi很高兴它帮助了我:)
是的,比我的答案好。我不知道这个函数存在;-)不用担心@happi我很高兴它能帮上忙。:)是的,比我的答案好。我不知道这个函数存在;-)