Am 2012-01-19 23:46, Jonathan N. Little meinte:
> cerr wrote:
>> Hi There,
>>
>> I'm trying to hide a div when my java script gets executed but it
>> doesn't seem to work.
>> My script looks like this, I see the message test popup but the div
>> doesn't disappear.
>> function closediv()
>> {
>>
>> var x=document.getElementsByName("emaildiv");
>> if(x)
>> {
>> alert("test");
>> x.style.visibility = 'hidden';
>> }
>> }
>> However when i add visibility:hidden; to my style declaration it seems
>> to work well. What's going on here?
>> Any hints or suggestions are appreciated!
>> URL:
http://pizzalita.com/index1.html
>
> DIVs don't have names. Use an ID.
>
>
> <div id="emaildiv" ...
>
> and then change your JavaScript:
>
> var x=document.getElementsByID("emaildiv");
The name of the method is getElementById().
>
> Also note that getElementsByName() returns a collection not a single
> element like getElementsByTagName() so to test for success would be
>
>
> if( x.length ) { ...
>
> and to change the property of first element would be:
>
> x[1].style.visibility = 'hidden';
This ain't some obscure language (like ColdFusion), the first element
would be x[0].
Gregor
--
http://vxweb.net