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>
question from:
https://stackoverflow.com/questions/6237673/cleanest-way-to-get-the-next-sibling-in-jquery 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…