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

javascript class style properties

P: n/a
If I have the following:

<style type="text/css">
..nd {
display : none;
}
</style>
<input type="checkbox" id="b1" class="nd"/>

how do I tell (in javascript) that the checkbox's display status is
currently none?

TIA
Regards
Paul
Jul 5 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Paul Lautman wrote:
If I have the following:

<style type="text/css">
.nd {
display : none;
}
</style>
<input type="checkbox" id="b1" class="nd"/>

how do I tell (in javascript) that the checkbox's display status is
currently none?
From a Matt Kruze post (wrapped for posting);

function getObjectStyleValue(obj,property) {
if (obj.currentStyle) {
return obj.currentStyle[property];
}
else if (obj.document && obj.document.defaultView
&& obj.document.defaultView.getComputedStyle) {
return obj.document.defaultView.getComputedStyle(obj,
'').getPropertyValue(property);
}
return null;
}

--
Rob
Jul 5 '06 #2

P: n/a
RobG wrote:
Paul Lautman wrote:
>If I have the following:

<style type="text/css">
.nd {
display : none;
}
</style>
<input type="checkbox" id="b1" class="nd"/>

how do I tell (in javascript) that the checkbox's display status is
currently none?

From a Matt Kruze post (wrapped for posting);

function getObjectStyleValue(obj,property) {
if (obj.currentStyle) {
return obj.currentStyle[property];
}
else if (obj.document && obj.document.defaultView
&& obj.document.defaultView.getComputedStyle) {
return obj.document.defaultView.getComputedStyle(obj,
'').getPropertyValue(property);
}
return null;
}
Cheers for that
Jul 5 '06 #3

P: n/a
Paul Lautman wrote:
RobG wrote:
>From a Matt Kruze post (wrapped for posting);
function getObjectStyleValue(obj,property) {
[snip]
Cheers for that
Check out a more robust version at:
http://www.javascripttoolbox.com/lib/util/

// Get the currently-applied style of an object
css.getStyle = function(o, property) {
if (o==null) { return null; }
var val = null;
var camelProperty = css.hyphen2camel(property);
// Handle "float" property as a special case
if (property=="float") {
val = css.getStyle(o,"cssFloat");
if (val==null) {
val = css.getStyle(o,"styleFloat");
}
}
else if (o.currentStyle && defined(o.currentStyle[camelProperty])) {
val = o.currentStyle[camelProperty];
}
else if (window.getComputedStyle) {
val = window.getComputedStyle(o,null).getPropertyValue(p roperty);
}
else if (o.style && defined(o.style[camelProperty])) {
val = o.style[camelProperty];
}
// For color values, make the value consistent across browsers
// Convert rgb() colors back to hex for consistency
if (/^\s*rgb\s*\(/.test(val)) {
val = css.rgb2hex(val);
}
// Lowercase all #hex values
if (/^#/.test(val)) {
val = val.toLowerCase();
}
return val;
};
--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.