开发者

jquery not finding image in IE

Answered

I have a piece of jquery code that works in FF but not in IE. Adding to my confusion is that an almost identical piece of code works in both.

I have a div with class of imghead and imghead2. Depending on the src of the first img tag I want to append a piece of code

This code works in both browsers:

$(".imghead2 img[src=/img/image.gif]").each(function() {
        $(".imghead2").prepend('<a href="#"><img src="/img/image" border="0" id="anniversary" alt="" /></a>');          
 });

This Code only works in FF

  $(".imghead img[src=/img/mh_image.jpg]").each(function() {
        $(".imghead").prepend('<a href="#"><img src="/img/image.png" border="0" id="anniversary" alt="" /></a>');
         }); 

As far as I can see these snippets are identical - I actually just pasted the working one and changed the imghead2 to imghead. In addition if I remove the $(".imghead img[src=/img/mh_image.jpg]").each(function() { It prepends properly.

Edit: Here is the html:

<div id="header">
    <div class="imghead2" style="float:right"><img src="/img/image.gif" alt="" width="314" height="11" border="0" /></div>
    <div class="imghead" style="float:left"><a href="/"><img src="/img/mh_image.jpg" alt="" width="260" height="60" border="0" /></a><noscript><p class="noScriptHead">This page uses Javascript. Your browser either doesn't support Javascript or 开发者_JAVA技巧you have it turned off.<br />To see this page as it is meant to appear please use a Javascript enabled browser.</p></noscript></div>
</div>


Added a * before the = and it seems to be running fine now:

$(".imghead img[src*='/img/mh_image.jpg']").each(function() {
        $(".imghead").prepend('<a href="#"><img src="/img/image.png" border="0" id="anniversary" alt="" /></a>');
         });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜