Home › Forums › JavaScript › how to set attributes for images only in IE 8 and below?
- This topic is empty.
-
AuthorPosts
-
December 26, 2013 at 2:53 pm #159149raj080288Participant
Hi,
I am using a plugin called mobify.js to help with my responsive images. However, to avoid blocking the javascript, the documentation suggests adding a ‘x’ to the image source so it would be displayed as
<img x-src="..." />
.This does not render or work in IE 8 and below so I need a way of changing the image tag back to
<img src="..."'>
for IE 8 and below only.So far I have tried the code below but IE is not recognizing it.
//sets the image source equal to the x-src element.setAttribute(‘src’,element.getAttribute(‘x-src’)); //removes x-src element.removeAttribute(‘x-src’);
Thanks in advance.
Raj
December 27, 2013 at 4:22 pm #159195raj080288ParticipantHi, can someone help please?
Thanks
December 28, 2013 at 7:34 am #159214JamesParticipantEDIT: Solution misinterpreted.
December 28, 2013 at 9:40 am #159217raj080288ParticipantHi James,
I totally understand what you said and am aware of how to create stylesheets to target IE however, I need the code that can chance the
<img src="x-img">
back to the normal<img src="img">
ONLY for ie which is 8 and lower.Hope this makes sense?
Raj
December 28, 2013 at 10:02 am #159218SenffParticipantCreate a jQuery file that contains something like this (untested):
$(document).ready(function(){ $('img').each(function(i) { srcvalue = $(this).attr('x-src'); $(this).attr('src',srcvalue).removeAttr('x-src'); }); });
Then only load it for IE8 and lower by putting something like this in the HEAD (untested):
<!--[if lt IE 9]> <script src="thatIE8script.js" type="text/javascript"></script> <![endif]-->
December 30, 2013 at 7:19 pm #159324raj080288ParticipantHi Senff,
Thanks for the post, and sorry for the late reply been busy over the Christmas period!. That solution would only remove the
<img x-src
> code, I need a code so it is also replaced back to the original<img src>
.I am also looking for a javascript work around if possible. Tried so many things but just not working!!!
Have a good new year anyway!
Thanks,
Raj
December 30, 2013 at 8:27 pm #159326SenffParticipantMy solution IS a Javascript solution and should remove the x-src, as well as add the src. It should change <img x-src=”blabla.gif> to <img src=”blabla.gif>.
Can you show where you implemented it perhaps so I can check why it doesn’t work?
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.