Hello I am writing a script that will replace the src of an image when the user hovers over it. I am using jquery and regex to accomplish this and have tested it on my local server but the src of the images on the live server is different and uses a non-relative path.
Here is my code
$(document).ready(function() {
$("img.imagefield").mouseover(function() {
var regex = "^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/sites/all/files/[a-zA-Z]*";
var src = $(this).attr("src").match(regex) + "_silly";
$(this).attr("src", src);
})
.mouseout(function() {
var src = $(this).attr("src").replace("_silly", "");
$(this).attr("src", src);
});
});
the regular expression should match something like
http://www.examplesite.com/sites/all/files/John.jpg?161717717 (the random numbers at the end are just some added junk drupal throws on for some reason)
and then when you hover over the image it should be
http://www.examplesite.com/sites/all/files/John_silly.jpg?161717717
and then return to the original src when you mouseout.
and change it to