Re: Setting several styles within one javascript function
- From: Michael Winter <m.winter@xxxxxxxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 16:02:11 GMT
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. .
- Follow-Ups:
- Re: Setting several styles within one javascript function
- From: Spartanicus
- Re: Setting several styles within one javascript function
- References:
- Setting several styles within one javascript function
- From: Spartanicus
- Re: Setting several styles within one javascript function
- From: Dylan Parry
- Setting several styles within one javascript function
- Prev by Date: Re: Setting several styles within one javascript function
- Next by Date: Re: Setting several styles within one javascript function
- Previous by thread: Re: Setting several styles within one javascript function
- Next by thread: Re: Setting several styles within one javascript function
- Index(es):