Reputation: 20484
The following code I have load on when a link is clicked:
$('.ops .menu .panel a').on('click',function(){
$('.ops .lay').css('opacity',0.1).load($(this).attr('href'), function(){ $('.ops .lay').css('opacity',1) });
$(this).parent().parent().find('a').removeClass('active'); $(this).addClass('active');
return false
});
I want this code to also be insde another load function. Do I have to repeat it or is there another way. Can it be stored somewhere?
Upvotes: 0
Views: 76
Reputation: 26940
function act(){
$('.ops .lay').css('opacity',0.1).load($(this).attr('href'), function(){ $('.ops .lay').css('opacity',1) });
$(this).parent().parent().find('a').removeClass('active'); $(this).addClass('active');
return false
};
$('.ops .menu .panel a').on('click', act);
use act
method somewhere else too :)
Upvotes: 2
Reputation: 46657
Save the function as a variable and reference it from both places:
var myFunction = function() {
$('.ops .lay').css('opacity',0.1).load($(this).attr('href'), function(){
$('.ops .lay').css('opacity',1)
});
$(this).parent().parent().find('a').removeClass('active');
$(this).addClass('active');
return false;
};
$('.ops .menu .panel a').on('click', myFunction);
// i assume by "load function" you meant document ready, but you get the idea
$(document).ready(myFunction);
Upvotes: 4