user695868
user695868

Reputation:

function to add to inline html style attribute not working in IE

I am currently using this function to add to the style attribute of posternew imgframe div's:

$(function () { $('.posternew .imgframe').each(function () { 
    $(this).attr("style", $(this).attr("style").replace("background:", ""));
    $(this).attr('style', 'background:url(images/new.png),' + $(this).attr('style')); 
    });  
});

This works perfectly in Chrome and Firefox, but will not under IE 9 or 10. I've tried formatting it slightly differently, but to no avail. Any ideas as to why this will not work in IE?

This creates this html in Chrome and Firefox:

<div class="imgframe" style="background:url(images/new.png), url(images/boxart/blah.jpg);"></div>

But in IE shows:

<div class="imgframe"/>

Upvotes: 0

Views: 357

Answers (1)

VisioN
VisioN

Reputation: 145478

How about that?

$(".posternew .imgframe").css("background-image", "url('images/new.png')");

No need in parsing style attribute, just use .css().

Upvotes: 3

Related Questions