2

$('.delete_button').click()イベントの親にアクセスしてpタグを見つけ、その内容を置き換えようとしていますが、このコードのどこで間違っているのかわかりません。

jquery:

//inside $('.delete_button').click() evvent
$(this).parent('.news_container').find('p').html(no_featured_news).removeClass('existing').addClass('description');

HTML:

<div class="news_container">
   <p class="existing">Lorem Lipsum</p>
   <button class="delete_button" data-id="1605361"></button>
</div>

上記のjqueryコードがpタグを見つけられない理由はありますか?私は何が間違っているのですか?

アップデート

jQueryクリックイベント:

$('.delete_news_order').click(function(){

  var image = $(this);
  if (id===undefined)
    id = $(this).data('id');

  console.log($(this).data('id'));

  $.post('do.php', { OP: "delete_order", id: id }, function(result){

      $(this).siblings('p').html(no_featured_news).removeClass('existing').addClass('description');
      ...
4

1 に答える 1

3

それはうまくいくはずです。siblingsただし、代わりに使用できます。

$('.delete_button').click(function() {
    $(this).siblings('p')
        .html("Text")
        .removeClass('existing')
        .addClass('description');
});
于 2012-05-31T11:28:04.757 に答える