I have the following code:
alert($("div", data).attr("style.background"));
I would like to select the colour value on this code:
<div id = "test"style="font-family: serif; font-size: x-large; font-weight: bold; background: #5e5; text-align: center; margin: 0px; padding: 16px;">
I am unsure what to use instead of style.background.
Any help would be amazing, thanks!
Edit:
More Code
success: function (data) {
alert(data);
alert($("div", data).css("background"));
},
As for why your jQuery selector
$('div',data)isn’t working, that’s becausedatais a string, not a jQuery object. To get what you want, you need to do:This will get you the
divcontained within thedatastring.If all you want is the color, try:
However, this will return the color in
rgb(...)format, as jQuery converts all color codes to rgb.However, if you want the actual value used in the
styleattribute, you’ll need to parse the attribute itself to find your answer:jsFiddle Demo