Reputation: 21150
I'm having trouble with a jQuery code at the moment, I know WHERE the problem lies, but I don't know what the problem is exactly. Probably very basic, but I'm new to this.
You can see a (non)working fiddle here: http://www.jsfiddle.net/CvZeQ/
Basically I want to set different .click function based on whatever is selected (I have 5 image maps, each with a different #mapname, and want each to pertain to a different variable (answer1, answer2, answer3...) so as to store the selected 'answer' for each map.)
Here is the code I'm using for one of the maps:
$(window).load(function(){
//Get cookies when page loaded
var useranswers=$.cookie('survery');
useranswers= JSON.parse (useranswers);
// do something with previous answers
//#shape functions
$('#shape area').hover(
function(e){
$('#'+ this.alt).addClass('hover');
},
function(e){
$('#'+ this.alt).removeClass('hover');
}
).click(
function(e){
$('img.selected-region').removeClass('selected-region');
},
function(e){
$('#'+ this.alt).addClass('selected-region');
},
function(e){
var answer1 = $(this).attr("class");
});
});
I know the problem lies somewhere with the .click function, but I'm not entirely sure what I've done wrong. Any help would be greatly appreciated.
Upvotes: -1
Views: 72
Reputation: 723598
.click()
doesn't accept three callbacks, it only accepts one. If you intend for all three to execute in sequence on click, try combining them all to a single function(e)
, like so:
.click(
function(e){
$('img.selected-region').removeClass('selected-region');
$('#'+ this.alt).addClass('selected-region');
var answer1 = $(this).attr("class");
});
Also, change
$(window).load(function(){
to
$(document).ready(function(){
Upvotes: 3