SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    using bind() and live() in jquery

    I'm trying to make an upload form that allows you to create multiple inputs. Each input has a delete button to remove it. I've tried both live() and bind().

    I'm having difficulty getting the delete button to work on appended elements.

    What do I have wrong here?

    Thanks
    E

    Code JavaScript:
    //image uploaders
     
    		loader='<li>'+
    		'<label>Upload Image</label>'+
    		'<input id="upload_image" type="text" size="36" name="upload_image" value="" style="width:360px;" />'+
    		'<input id="upload_image_button" type="button" value="Upload Image" style="width:100px;" />'+
    		'<input class="delete" type="button" value="X" style="width:20px;float:right;" />'+
    		'</li>';
     
    		jQuery('#add_image').live("click", function(){
    			jQuery('#image_uploaders').append(loader);
    			return false;
    		});
     
    		jQuery('.delete').click(function(){
    			jQuery(this).parent().remove();
    		});

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,075
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    You mean

    Code JavaScript:
    jQuery('.delete').live('click', function(){
       jQuery(this).parent().remove();
    });

    doesn't work? It should ...
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    967
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I see. I thought the bind was used when the element was created. Thanks it works now!
    E


Bookmarks

Posting Permissions

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