Iladarsda
Iladarsda

Reputation: 10692

jQuery - how to access variable from outside of the form

Following example:

var ClickedTab = $(this).attr("href").substring(1);

$('#loaderDiv').load(TrimedClickedTab + '.html', function() {

    if (ClickedTab == 'quick-form') {

         console.log(' Quick FOR<');

    }
});

Currently ClickedTab inside if statement will be undefined, how to access this variable from inside of the function withou changing the syntax?

Upvotes: 1

Views: 82

Answers (1)

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76910

One thing you could do is to use data() to save your info so that you can get it back later

var ClickedTab = $(this).attr("href").substring(1);
//save your data to use it later
$('#yourform').data('ClickedTab', ClickedTab );

$('#loaderDiv').load(TrimedClickedTab + '.html', function() {

    if ($('#yourform').data('ClickedTab') == 'quick-form') {

         console.log(' Quick FOR<');

    }
});

But in your case you should be able to see it just as is as you can see from thois fiddle

http://jsfiddle.net/5QEfm/

So the error must be somewhere else

Upvotes: 2

Related Questions