Reputation: 51
I am using this script to load most of the pages in #content. I was wondering how should I go about enabling and disabling certain links from being affected. The problem is, on some pages I want the script to affect my main menu links completely, and on others, I want it to affect my menu partially so that I can load other pages and sub-domains.
$(document).ready(function() {
$('#content').load('login.php')
$(document).on('click','a',function() {
var page = $(this).attr('href');
$('#content').load('' + page + '.php')
return false;
});
});
So should I simply work with $(document).on('click','a',function() {?
to handle this? Is there a way to use a class tag to disable links from being affected? Or perhaps a better way to go about this? Thanks.
Upvotes: 1
Views: 142
Reputation: 6470
I would write the event handler like:
$("a:not('.some-class')").click(function() {
// etc.
});
Upvotes: 1
Reputation: 97672
You can give the links you don't want affected a class then exclude the class in your selector
<a href="..." class="noajax">...</a>
$(document).on('click','a:not(.noajax)',function() {
Upvotes: 1