Help us understand the problem. What is going on with this article?

IE11でbackground-imageのJQueryが反映されない...!!

問題となったコード。

html
<div id="image_area"></div>
JQuery
$("#image_area").css("background-image","url(画像パス)");

このコードでは、Chrome、FireFoxでは動作するが、IE11では動かず。
いろいろ原因を探って、たどり着いた答えがコレ。

修正後
$("#image_area").css({
    "background-image": 'url("画像パス")',
});

IE11でbackground-imageプロパティを指定するときは

1. { "background-image": 値 } の形式で書く
2. 画像パスはダブルクオーテーションで囲む

必要があるようです。なんでこうしないといけないのかはわからないですが...
はやくIE絶滅しないかな♪

参考にしたところ
jQueryで背景画像を変える時にIEでの対処法【JS】
背景画像をJavaScriptで書き換える

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした