Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts

    jQuery: addClass at onclick

    Hi,
    I would like to add a class to the <li> or <a> tag when a particular link is clicked. This is the html,

    Code:
    <ul>
                <li><a href="#" onclick="loadPage('1.php'); return false;">1</a></li>
                <li><a href="#">2</a></li>
                <li><a href="#">3</a></li>
    </ul>
    jquey's ajax,

    Code:
    function loadPage(parameter) {
    this.addClass('current');
    $("#content").html('<div id="ajaxloader"><p><img src="img_iconies/loader_0.gif"/> loading...</p></div>');
    $("#content").load( "incl_contents/" + parameter, {}, function(){ //calling the ajax then with a callback afterwards
     	$("#content").css({display:'none'})
    	.fadeIn("slow");
     	});
    }
    it works fine until i put this line in,

    Code:
    this.addClass('current');
    I think it is probably it is incorrect the way i try to add the class to the link.

    Many thanks if u have any ideas.

    Lau

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you tested it?

    That should work, and add the class to the anchor.
    Fiji Web Design - where i do Joomla Web Design
    Bucabay.com - My blog

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by digital-ether View Post
    Have you tested it?

    That should work, and add the class to the anchor.
    yes i did but it didnt work... i have tried this but it doesnt work too,

    Code:
    $(this).addClass("current");


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •