By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

toggle node with checkbox

P: n/a
Hello,

I currently have a hyperlink to toggle the node, showing and hiding
the list. Could someone show me how to use a checkbox instead of the
hyperlink to do the same thing? Thanks.
I tried the following line but the node's nextSibling becomes
[<u>Fruits:</u>] instead of <div>. Then I tried node.
nextSibling.nextSibling but it didn't work. Please help!

<input type="checkbox" onclick="Toggle(this)" id="Fruits"><u>Fruits:</
u><div>

===========

<html>

<script language="JavaScript">

function Open(node)
{

node.nextSibling.style.display = '';
}

function Close(node)
{

node.nextSibling.style.display = 'none';
}

function Toggle(node)
{

if (node.nextSibling.style.display == 'none')
{
Open(node);
}

else
{
Close(node);
}

}

</script>
<a onclick="Toggle(this)" id="Fruits"><u>Fruits:</u></a><div>
<table>
<tr>
<td>Orange</td>
<td>Apple</td>
<td>Pearl</td>
</tr>
</table>
</div>

</html>
Oct 12 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 2008-10-12 07:23, st***********@gmail.com wrote:
I currently have a hyperlink to toggle the node, showing and hiding
the list. Could someone show me how to use a checkbox instead of the
hyperlink to do the same thing? Thanks.
I tried the following line but the node's nextSibling becomes
[<u>Fruits:</u>] instead of <div>. Then I tried node.
nextSibling.nextSibling but it didn't work. Please help!
node.nextSibling.nextSibling will work if you change it in all three
functions.

Before you wonder your script isn't working as expected, check your
HTML. What you're using in your test isn't remotely valid:
http://validator.w3.org/
- Conrad
Oct 12 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.