jquery: how to find an element which is comming 2 elements before current element
- by erkan
Hi guys...
i have a markup which look like this:
<h3>Paragraf3-dummytext</h3>
<p>
<a name="paragraf3">
Quisque id odio. Praesent venenatis metus at tortor pulvinar varius. Lorem ipsum dolor sit
</a>
</p>
what i want to do is to find all 'a' tags with 'name' attribute and find the 'h3' tag for that anchor; im trying to do it like this:
var paragraf = [];
var paragrafheading = [];
$('a[name]').each(function() {
paragraf.push($(this).attr('name'));
paragrafheading.push($(this).prev().text());
but it does not work becouse there is a 'p' tag around the text. Any suggestions would be appreciated. Thanks