0

以下のようなリストに多くのli要素があります。ul

<li id="filesOrderArray_dynamic_number>">
  <a href="javascript:void(0)" class="remove_from_filestock">
    <img src="ui_icons/cross-small.gif" title="Remove" rel="more_dynamic_numbers_here" />
  </a>
  <a href="javascript:void(0)" class="title_filestock">
    <img src="ui_icons/properties-small.gif')?>" title="Properties" rel="more_dynamic_numbers_here" />
  </a>
  <a href="some_address" target="_blank" class="filestock_preview fancybox" rel="filestock">
    Some Title
  </a>
</li>

jQuery関数があります。同じタグ内a.filestock_previewをクリックすると、テキストを選択しようとしています。a.title_filestockli

function title()
{
  $('a.title_filestock').click(function(e) {
    e.preventDefault();
    var value = $(this).closest('a.filestock_preview').text(); alert(value);   
  });
}
title();
4

1 に答える 1

1

この.closest()メソッドは祖先要素を調べます。.filestock_preview選択する要素は、要素の兄弟.title_filestockです。すぐ後に続くので、次を使用できます.next()

var value = $(this).next().text();

.siblings()または、セレクターを使用して渡すこともできます。

var value = $(this).siblings('a.filestock_preview').text();
于 2012-08-08T06:56:46.883 に答える