views:

4072

answers:

3

Hi! I have a div:

<div style="test" id="someElement"></div>

Is there any way to check if the certain element:

$("#someElement")

has a particular css style (in my case, "test").

Thank you very much!

+5  A: 
if($('#someElement').hasClass('test')) {
  ... do something ...
}
else {
  ... do something else ...
}
Darin Dimitrov
thank you very much.perfect solution
ifesdjeen
A: 

i've found one solution:

$("#someElement")[0].className.match("test")

but somehow i believe that there's a better way!

ifesdjeen
+5  A: 

CSS Styles are key-value pairs, not just "tags". By default, each element has a full set of CSS styles assigned to it, most of them is implicitly using the browser defaults and some of them is explicitly redefined in CSS stylesheets.

To get the value assigned to a particular CSS entry of an element and compare it:

if ($('#yourElement').css('position') == 'absolute')
{
   // true
}

If you didn't redefine the style, you will get the browser default for that particular element.

DrJokepu
wow. didn't know that.thank you!!
ifesdjeen