1

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.

2 Answers 2

1

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()  {
Sign up to request clarification or add additional context in comments.

Comments

1

I would write the event handler like:

$("a:not('.some-class')").click(function() {
  // etc.
});

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.