Javascript jQuery查找和替换<;strong>;附件前的标签
我想删除当用户执行搜索时应用于文本的标记 要追加的html如下所示:Javascript jQuery查找和替换<;strong>;附件前的标签,javascript,jquery,html,replace,Javascript,Jquery,Html,Replace,我想删除当用户执行搜索时应用于文本的标记 要追加的html如下所示: $("body").on("click", ".search-results li", function(){ $(this).appendTo(".creating-wrapper .recipients"); }); 应该只是jQuery魔术 <li class="highlight-off" rel="<?php echo $userID?>"> <div class=
$("body").on("click", ".search-results li", function(){
$(this).appendTo(".creating-wrapper .recipients");
});
应该只是jQuery魔术
<li class="highlight-off" rel="<?php echo $userID?>">
<div class="left"><img class="photo" src="<?php echo photo($userID, 35)?>"/></div>
<div class="right">
<div class="name"><?php echo highlight($term, str_replace(" "," ", name($userID)))?></div>
</div>
</li>
这个怎么样
var $append = $( this );
$append.find( 'div.left' ).remove();
$append.find( 'strong' ).contents().unwrap();
$append.appendTo(".creating-wrapper .recipients");
几乎,但是我希望标记中的文本保留在那里。您的删除了div.left,但是它对强标记没有任何作用。但是,正如下面的答案所示,我不希望删除强标记中的文本,只希望删除标记本身,这样文本就不再粗体。
$("body").on("click", ".search-results li", function(){
$(this).find('div.left').remove();
$(this).find('strong').each(function() {
$(this).after($(this).text()).remove();
});
$(this).appendTo(".creating-wrapper .recipients");
});