http://jsfiddle.net/mplungjan/H9Raz/
After quite some tests with next('a') and such, I finally found one that worked. I just wonder why next('a') did not, or closest or similar. Are there cleaner ways to get at the href of the link after the checkbox I click?
$('form input:checkbox').click(function () {
alert($(this).nextAll('a').attr("href"));
});
<form>
<div>
<input type="checkbox" name="checkThis" value="http://www.google.com" />Check here<br/>
<a href="http://www.google.com">click here</a><br>
<input type="checkbox" name="checkThis" value="http://www.bing.com" />Check here<br/>
<a href="http://www.bing.com">click here</a>
</div>
</form>
next()
because the<br>
element is in the way. So,nextAll()
is indeed the best solution as far as I can tell.