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
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Problem with jQuery on('click')

    If you look at the link below the list refreshes once, but then never repeats again when you click refresh list. I'm sure it's just a simple mistake i've made somewhere but I can't seem to get it working.

    Can anyone help?

    http://jsfiddle.net/tomharto/5krc4/2/

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    To use .on() for all future elements it needs to be like so:

    Code:
    $(document).on(event,selector, handler)
    
    in your example:
    
    $(document).on('click', '.click',function(){
    What you have at the moment only applies to existing elements - so it works the first time, but doesn't re-attach the click event handler to the replaced elements.
    Use the W3C HTML Validator and CSS Validator to check your code and Firebug to see what css is applied to an element
    Read Steve Krug's book Don't Make Me Think - essential reading on web usability
    I don't recommend much, but I do recommend Clook for UK web hosting

  • Users who have thanked SB65 for this post:

    tomharto (04-11-2013)

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by SB65 View Post
    To use .on() for all future elements it needs to be like so:

    Code:
    $(document).on(event,selector, handler)
    
    in your example:
    
    $(document).on('click', '.click',function(){
    What you have at the moment only applies to existing elements - so it works the first time, but doesn't re-attach the click event handler to the replaced elements.
    Thank you . My bad for not reading the docs fully, I though on worked the same as live used to.


  •  

    Posting Permissions

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