I have many li elements in an ul list like below:
<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>
I have a jQuery function. I am trying to select the a.filestock_preview text when I click the a.title_filestock inside the same li tag.
function title()
{
$('a.title_filestock').click(function(e) {
e.preventDefault();
var value = $(this).closest('a.filestock_preview').text(); alert(value);
});
}
title();
The
.closest()method looks at ancestor elements. The.filestock_previewelement you want to select is a sibling of the.title_filestockelement. Since it immediately follows it, you can use.next():You could alternatively use
.siblings()and pass in the selector: