jQuery在appendTo </strong>之前查找并替换<strong>标签

时间:2012-12-07 01:57:15

标签: javascript jquery html replace

$("body").on("click", ".search-results li", function(){

    $(this).appendTo(".creating-wrapper .recipients");

});

我想删除用户执行搜索时应用于文本的<strong></strong>标记。

附加的html如下所示:

<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("&nbsp;"," ", name($userID)))?></div>

    </div>
</li>

另外,我还想做的另一件事就是删除整个<div class='left'></div>及其元素

谢谢!

2 个答案:

答案 0 :(得分:1)

应该只是jQuery魔术。

var $append = $( this );
    $append.find( 'div.left' ).remove();
    $append.find( 'strong' ).contents().unwrap();

$append.appendTo(".creating-wrapper .recipients");

答案 1 :(得分:1)

这个怎么样?

$("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");
});
相关问题