I’ve written a quick image swap class that switches images on hover by placing adding ‘_grey’ to the image src. The code works great throughout the site in all browsers apart from ie6. The substr doesnt seem to work properly here – any advice please!?
Code as follows –
$(document).ready(function() {
var initImg;
$('img.swapGrey').hover(function() {
initImg = $(this).attr("src");
var imgType = (initImg).substr(-4);
alert(initImg);
var greyImg = initImg.slice(0, -4) + "_grey" + imgType;
alert(greyImg);
$(this).attr("src",greyImg);
}, function() {
$(this).attr("src",initImg);
});
});
Use
slicerather thansubstr.substris non-standard, whilesliceis specified (including negative positions) in the ECMAScript 3 spec, and is supported in all the major browsers, including IE 6.