I am trying to determine if the <img>
element has inline CSS properties defined. If it does, I want to apply those CSS properties to its parent and remove the original CSS declaration.
This is my attempt at solving the issue:
var $el = $('.article > img');
$el.each(function () {
if ($(this).css("float") == "left") { $(this).parent().css("float","left"); }
if ($(this).css("float") == "right") { $(this).parent().css("float","right"); }
})
The img
tag may have CSS for float
, margin
, or both, or neither of them. However, my current code only handles one rule at a time.
Could someone please advise on how I can modify the code to handle both CSS rules?