I referenced this page, but I have to do something wrong: jQuery check if an element has a specific attribute
Basically, I want to add the class "img-left" if the image has the attribute style = "float: left" and "img-right" if style = "float: right;" My HTML looks like this:
<img class="content-img" style="float: left;" src="/images/my-img.jpg">
And I want it to look like this:
<img class="content-img img-left" style="float: left;" src="/images/my-img.jpg">
Here is what I tried:
if ($('.content-img').css('float' == 'left')) { $(this).addClass('img-left'); } else { $(this).addClass('img-right'); }
This results in a JS error, but I can't figure out why. Any help would be greatly appreciated.
Thanks, Vaughn
source share