jquery: how to find an element which is comming 2 elements before current element
Posted
by erkan
on Stack Overflow
See other posts from Stack Overflow
or by erkan
Published on 2010-03-29T09:30:26Z
Indexed on
2010/03/29
9:33 UTC
Read the original article
Hit count: 470
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
© Stack Overflow or respective owner