Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在exist div中添加HTML元素,但覆盖内容?_Jquery_Html - Fatal编程技术网

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 API
wrapInner

演示

代码

$('.title-post').wrapInner('<span>');
$('.title post').wrapInner('');

downvoter评论?我身体不好,需要帮助。你有什么意见?我不好,所以我需要帮助。不用担心@happi很高兴它帮助了我
:)
是的,比我的答案好。我不知道这个函数存在;-)不用担心@happi我很高兴它能帮上忙。:)是的,比我的答案好。我不知道这个函数存在;-)