Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-03-2011, 01:10 AM   PM User | #1
gilgimech
New Coder

 
Join Date: Mar 2010
Posts: 58
Thanks: 10
Thanked 3 Times in 3 Posts
gilgimech is an unknown quantity at this point
Check if css property exists with JS

I'm using ccs3PIE with my site. What I want to do is check if a DOM element has a css property like border-radius and then add a class to it.

The problem I'm having is that I don't know how to check for the css property. I've been searching for it for a couple of hours now and I can't find anything that seems to work.

Any ideas?
gilgimech is offline   Reply With Quote
Old 07-03-2011, 08:47 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,259
Thanks: 10
Thanked 532 Times in 526 Posts
devnull69 will become famous soon enough
You can do two things, with specific drawbacks

1. There are the methods getComputedStyle/getPropertyValue. Together they will tell you the current value of a specific CSS property.
Code:
window.getComputedStyle(element, null).getPropertyValue('border-radius');
BUT: It will always give you a result. This is because all of the CSS properties will have values even if they have not been set explicitly. So you can't tell the difference between border-radius 0 that has been set deliberately and border-radius 0 that has been set by default

2. Each element will expose its style attribute/property. So if the border-radius has been set using style="border-radius: ...." in HTML, this will give you the value
Code:
var myValue = element.style.borderRadius;
BUT: It will only work for inline HTML style attributes
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:33 AM.


Advertisement
Log in to turn off these ads.