user715449
user715449

Reputation: 183

jQuery change variable on click?

i am sure its a simple thing. But i cant find the solution. My Code:

var lang='de';

$('#en').click(function (){
    lang='en';
});

The variable dont change / updates on click, why?

Thanks!

Solution: works not local only on Webserver for me.

Upvotes: 1

Views: 31907

Answers (3)

aziz punjani
aziz punjani

Reputation: 25776

Maybe you are missing the document.ready ?

$(function(){
var lang='de';
    $('#en').click(function (){
        lang='en';
    });
}); 

Upvotes: 0

Gabe
Gabe

Reputation: 50493

I tried this and it seems to work fine for me. More than likely you have a scope issue.

jsFiddle

Upvotes: 1

Kris Krause
Kris Krause

Reputation: 7326

Sure it does. Here is the jsFiddle test -

http://jsfiddle.net/RfDCU/

With your Html revision it works too -

http://jsfiddle.net/RfDCU/1/

Are you sure the lang variable is within function scope?

Upvotes: 0

Related Questions