1

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.

3
  • 1
    Needs more info and code. Does #en exist at all? Commented Sep 21, 2011 at 20:39
  • the js is loaded after the html of before? Commented Sep 21, 2011 at 20:42
  • Ok it was simple, my code works at all but not local only on webserver it change de to en variable. Commented Sep 21, 2011 at 20:57

3 Answers 3

1

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

jsFiddle

Sign up to request clarification or add additional context in comments.

1 Comment

If you put alert(lang); outside $, it won't work.
0

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?

Comments

0

Maybe you are missing the document.ready ?

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.