I have a jquery that works by passing variables through the .hover function. I have a series of images that I would like to change if the mouse hovered over them. I could just write something like:
$("p").hover(function(){
$("p").css("background-color","yellow");
},function(){
$("p").css("background-color","pink");
});
For each image/div or whatever but this seems more time consuming. I tried using this short hand version which I wrote but nothing happens.
function acc(size,tog){e
if(tog){
$('#' + size + '_text').attr('src','assessts/icons/text_' + size + '_active.png');
if(current_acc != size){
$('#' + current_acc + '_text').attr('src','assessts/icons/text_' + current_acc + '.png');
}
}else{
$('#' + size + '_text').attr('src','assessts/icons/text_' + size + '.png');
if(current_acc != size){
$('#' + current_acc + '_text').attr('src','assessts/icons/text_' + current_acc + '_active.png');
}
}
}
$(function(){
$('#small_text').hover(acc('small',true),acc('small',false));
$('#med_text').hover(acc('small',true),acc('small',false));
$('#large_text').hover(acc('small',true),acc('small',false));
});
There are no error in the console log and the images don't change but if I change
$('#small_text').hover(acc('small',true),acc('small',false)); to
$('#small_text').hover(acc,acc);
The images don't change but that is because the value of 'size' is unidentified. But is there a way of using what I have wrote instead of having to set the same function for each image.