/    Sign up×
Community /Pin to ProfileBookmark

Get style attributes from class?

I need to find out if a div has the style of disply:none;. I can’t use obj.style.display because this attribute is being set in a class, not as an inline style. Is there anyway to get this info with javascript?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledMar 13.2009 — use standard method [b]getComputedStyle[/b] and for msie browser use currentStyle object.
<i>
</i>if(getComputedStyle)
getComputedStyle([i]element[/i], null).display; // DOM compliant browser
else [i]element[/i].currentStyle.display; // for msie
// replace [i]element[/i] with an element node;
Copy linkTweet thisAlerts:
@rnd_meMar 14.2009 — if you know the class that causes it to hide, you can see if it or any parents have that class attrib...

here is dual browser self-mutation function that grab applied styles:
[CODE]
function getstyle(obj, cAttribute) {
if (obj.currentStyle) {
this.getstyle = function (obj, cAttribute) {return obj.currentStyle[cAttribute];};
} else {
this.getstyle = function (obj, cAttribute) {return document.defaultView.getComputedStyle(obj, null)[cAttribute];};
}
return getstyle(obj, cAttribute);
}[/CODE]
Copy linkTweet thisAlerts:
@BengaltgrsauthorMar 14.2009 — Perfect, thank you both.
×

Success!

Help @Bengaltgrs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...