Reputation: 2550
i want to select all html inside div that has style attribute on it.. here is fiddle url Jsfiddle Link
var testst = $('div').css('margin');
alert(testst.html());
i am not able to get result.
Upvotes: 0
Views: 12995
Reputation: 318588
Use an attribute selector:
$('div[style]')
However, using this to find an element with a specific style (CSS rule) is a bad idea. It will only work for inline styles actually set using style="whatever"
and your attribute value in the selector (div[style="whatever"]
) would have to match the attribute exactly.
So... the proper way to do it is to add a class
attribute to the relevant elements and select them using this class (div.whatever
for class="whatever"
or class="foo whatever bar"
).
If you still need to find elements with a certain CSS rule the most reliable way would be to iterate over all of them and check if they have the given style:
$('div').filter(function() {
return $(this).css('whatever') == 'the_value';
});
Upvotes: 13