I have this code to give me a rollover on submit buttons, and I\'m trying to make it more generic:
$(\'.rollover\').hover(
function(){ // Change
$('.rollover').hover(
function(){ // Change the input image's source when we "roll on"
var t = $(this);
t.attr('src',t.attr('src').replace(/([^.]*)\.(.*)/, "$1-over.$2"));
},
function(){
var t= $(this);
t.attr('src',t.attr('src').replace('-over',''));
}
);
To manipulate the file name and append "-over" you simply have to do some Javascript string manipulation, like this:
function appendOver(srcPath){
var index = s.indexOf('.');
var before = s.substr(0, index);
var after = s.substr(index);
return before + "-over" + after;
}
This should return the original filename (in all possible formats) and add the '-over' string just before the extension dot.
You should be able to use a regex replace to modify your source path. Like this:
srcPathOver = srcPath.replace(/([^.]*)\.(.*)/, "$1-over.$2");
More on JavaScript regexes here
As far as how you're doing it, I'd make sure that you define your srcPath variable like this
var srcPath;
$('.rollover').hover(...
The code you have above makes it look like srcPath is a global variable, which is not what you want.