medihack
medihack

Reputation: 16627

Check if var contains CSSStyleRule (get object name)

I need to check if a variable contains a CSSStyleRule. When using window.console.log(myvar) it tells me CSSStyleRule { constructor=CSSStyleRule, type=1, more...}, but when I use typeof myvar it just tells me object.

How can I check if it is really a CSSStyleRule?

Upvotes: 1

Views: 487

Answers (2)

Šime Vidas
Šime Vidas

Reputation: 185963

This should do it:

myvar instanceof CSSStyleRule

This expression returns true/false.

Upvotes: 2

typeof
typeof

Reputation: 5932

You can check to see if the object has the selectorText property:

if(myvar.selectorText) {

    ... 

}

Upvotes: 1

Related Questions