how to hide element

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

how to hide element

Post by yacahuma »

Hello,

I need a javascript that given the id(or name) of an element return me it's 'p' parent

ex

Code: Select all

<p><label for="x1"><input name="x1"></p>
<p><label for="x2"><input name="x2"></p>


function getParentOf("x1")
{
   //
}
Why?

I want to hide and show different elements of the form.

I could assign and id to each 'p' and that works but I thought it will be nicer if I dont have to give a name to every 'p' element
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Look up Javascript DOM scripting.

While you could probably find it in 5 minutes if you bothered to check google, I'm feeling generous - what you're looking for is something like:

Code: Select all

document.getElementById('x1').parent;
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

thank you

Post by yacahuma »

Well I was not sure what I was looking for + I feel better asking it here.


Thank you for the answer.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

parentNode.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

i get an error

Post by yacahuma »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I get an error on this. document.getElementById(id) has no properties

[syntax="html"]
<html>
<head>
<title>Page title</title>
<script type="text/javascript" src="calendarDateInput.js">
/***********************************************
* Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
* Script featured on and available at http://www.dynamicdrive.com
* Keep this notice intact for use.
***********************************************/
</script>
<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id).parentNode;
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>
</head>
<body>
<a href="#" onclick="toggle_visibility('orderdate');">toggle</a>
<form>
<p><label for="orderdate">Date:</label><script>DateInput('orderdate', true, 'DD-MON-YYYY')</script></p>
</form>
</body>
</html>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: i get an error

Post by Zoxive »

yacahuma wrote:I get an error on this. document.getElementById(id) has no properties

Code: Select all

<p><label id="orderdate" for="orderdate">Date:</label><script>DateInput('orderdate', true, 'DD-MON-YYYY')</script></p>
... You didn't give the Label an Id.
Post Reply