On Feb 18, 9:15 pm, Charlie22 <ch...@post.cz> wrote:
> Hi all,
> I have trouble passing value as selector value to other function.
>
> $(document).ready(function(){
>         var id = 'Test';
>         $('#Name').keyup(function(){
>                 id = '#Mobil';

If you want variables to be local to their enclosing function, declare
them with var.

The variable id has a closure to id in the outer function. Before the
keup runs, id is 'Test'. Afterward, its value is "#Mobil".

>         });
>
>         $(id).click(function(){

I guess that should be:

       $('#' + id).click(function(){


>         console.log(id);

This id also has a closure to the outer id.

>         });
>
> });
>
> I am getting on console value "#Mobil" but $(is) is using value
> "Test". Thx for help in advance.

All the id variables above refer to the same property of the same
activation object (i.e. they are essentially the same variable).
Modifying any one of them modifies the others.


--
Rob

Reply via email to