Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an element, from the element how do i know whether it has the inline style applied or not?

example :

html :

<span style="border:1px solid red;">Testing</span>
//<span>Testing</span> //without style as well getting some in build info

js :

var sty = $('span').prop('style');
console.log(sty); //it always consoles something!

Jsfiddle

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
133 views
Welcome To Ask or Share your Answers For Others

1 Answer

var sty = $('span').is('[style]');
if(sty)
{
  //style is present
}
else
{
  //style is not present
}

Demo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...