Simple jQuery syntax help, don't know where I've gone wrong

Posted by Jascination on Stack Overflow See other posts from Stack Overflow or by Jascination
Published on 2011-01-10T06:39:46Z Indexed on 2011/01/10 6:53 UTC
Read the original article Hit count: 169

Filed under:

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.

© Stack Overflow or respective owner

Related posts about jQuery