jQuery
New Wave Javascript
discuss » Selecting next sibling
Posted: Fri Mar 3 12:12:49 EST 2006
From: Klaus Hartl <
office at stilbuero.de
>
Hi Corey,
thanks for the tip, but this won't work with the following html:
<div>
<h3>Test</h3>
<p>One</p>
<h3>Test 2</h3>
<p>Two</p>
<h3>Test 3</h3>
<p>Three</p>
</div>
Therefore I wanted to select only the next sibling... but thank you anyway!
Regards,
Klaus
Corey Jewett wrote:
>
Like this:
>
>
<html>
>
<head>
>
<script type="text/javascript" src="http://jquery.com/src/
>
debug/"></script>
>
>
<script type="text/javascript">
>
window.onload = function () {
>
$("h3").click(function() {
>
$(this).find("../p").toggle();
>
});
>
}
>
</script>
>
</head>
>
<body>
>
<div>
>
<h3>Test</h3>
>
<p>One</p>
>
<p>Two</p>
>
</div>
>
>
<div>
>
<h3>Test 2</h3>
>
<p>One</p>
>
<p>Two</p>
>
<p>Three</p>
>
</div>
>
</body>