You can do it using .prev()
and .find()
or .children()
, like this:
$('.btn').prev('h2').find('a').attr('href');
You can give it a try here. The <a>
isn't a sibling so .prev()
won't won't work, you have to go back to the <h2>
which is a sibling, then go inside it to get the <a>
itself.
Nick Craver
2010-08-18 19:17:14