You are here: Re: Setting several styles within one javascript function « HTML « IT news, forums, messages
Re: Setting several styles within one javascript function

Posted by Michael Winter on 09/29/05 19:02

On 29/09/2005 16:35, Dylan Parry wrote:

> Using a pointed stick and pebbles, Spartanicus scraped:
>
>> function panel() {
>> document.getElementById('panel').style.display='hidden';

The value, hidden, doesn't apply to the display property, so this is a
CSS issue, not one of scripting. So, which is it: display/none, or
visibility/hidden?

A well-written script will be robust, and test its environment before
using any features. In this instance, though, it might be better to
prepare beforehand:

/* Establish if the getElementById method is implemented by the
* host. If not, create a replacement so that the method can be
* called successfully, even if the result will never be viable.
*
* Support for older, obscure object models can be added here.
* See the clj FAQ notes with regard to 'IDed Element Retrieval'.
*/
if(!document.getElementById) {
(document.getElementById = function() {
return null;
}).notViable = true;
}

function setStyle(element, property, value) {
(element.style || element)[property] = value;
}

function panel() {
var content, panel;

if((panel = document.getElementById('panel'))
&& (content = document.getElementById('content')))
{
setStyle(panel, 'display', 'none');
setStyle(content, 'marginLeft', '30px');
}
}

This is not necessarily the best alternative. It may depend on what the
rest of the code does.

[snip]

> I had problems with a similar function a while back. IIRC the problem
> was caused by having the /wrong kind of quotes/ and changing them to "s
> made all the difference. I might be wrong, of course ;)

Probably. There is no difference between single and double quotes in
ECMAScript.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация