2011-10-21 3 views
1

申し訳ありません質問のタイトルが明確でない場合は、実際には私は言葉でそれを記述することはできません!Jqueryのコンテンツ== smthなら?

私はファンシーミュージックプレーヤーを使用します:http://codecanyon.net/item/fancy-music-player-v20-jquery-plugin 私はメインプラグインファイルを編集できませんので、この方法でそれをしなければなりません!

私は同じ内容を持つ2つのリストがあります: ..私は最初にリスト内の項目を削除することができ

<ul id="list1"> 
    <li><em> item one </em> <a class="delete" href="#">Delete</a></li> 
    <li><em> item two </em> <a class="delete" href="#">Delete</a></li> 
    <li><em> item three </em> <a class="delete" href="#">Delete</a></li> 
</ul> 

<ul id="list2"> 
    <em> item one </em> 
    <em> item two </em> 
    <em> item three </em> 
</ul> 

をしかし、私はそれがunforsantly同じテキスト を持っている場合は、あまりにも#のLIST2内の項目を削除したいですここでは...

答えて

2

TRY -

$(".delete").live('click',function(eve) { 
    eve.preventDefault(); 
    var titleItem = $(this).parent().find('em').text(); 
    $(this).parent().find('em').remove(); 
    $("#list2").find("em:contains('" + titleItem + "')").remove(); 
});  

デモ - http://jsfiddle.net/pJmTF/

+0

それはだ、あなたは非常に多くのipr101ありがとうようやく正常に動作します:) – Ahmad

1

$(".delete").live('click',function(eve) { 
     eve.preventDefault(); 
     // 1- delete item here in the first list 
     // it's ok 

     // 2- delete the same item in the second list ('#list2') using text inside <em> ? 
     var titleItem = $(this).parent().find('em').text(); // i get here (item one or item two .. etc . depends on the item clicked above) 
     // here I want to see if this titleItem == ('#list2 em').text .. so delete it too 
     // I have to use the conent here cuz I can not edit to the main jquery plugin :(

    }); 

感謝:私はIDを使用することはできませんので、私は方法は、このような何かをしたいをチェックしてください。

テキストを変数に保存し、list2で.each()関数を使用して検索する必要があります。

$(".delete").live('click',function() { 
    var t = $(this).parent().find('em').text(); 
     // 1- delete item here in the first list 
    $(this).parent().remove(); 
     // 2- delete the same item in the second list ('#list2') using text inside <em> ? 
    $('#list2 em').each(function(){ 
     if($(this).text()==t) $(this).remove(); 
    }); 
      event.preventDefault(); 
    }); 
2
$(".delete").live('click',function(event) { 

    var titleItem = $(this).parent().find('em').text().trim(); 

    $("#list2 li").each(function(i, item){ 
     $item = $(item); 
     if($item.find('em').text().trim() === titleItem){ 
      $item.remove(); 
     } 
    }); 

}); 

jsfiddle here

+0

パーフェクト、ありがとうmorgancodes :) – Ahmad

+0

.trim()でうまく触れます。 – bozdoz

関連する問題