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 2 of 2

Thread: Help jquery...

  1. #1
    New to the CF scene
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help jquery...

    This is my script which appends the response on the page....but the appended buttons are not working.
    1. onclick not working;
    2. .live() notworking .

    but if i write any function after this line it works.
    $("#responseWrapper").append(htmldata)(in the success function)

    it means for handling appended items i hv to write query inside the success function ???
    is there another way??

    PHP Code:
    $(document).ready(function() {
     var 
    db = $("#db").val();
                var 
    homepage = $("#homepage").val();
                var 
    dataString 'db=' db '&homepage=' homepage
                
              
                
                
    jQuery.ajax({
                
    type"GET",
                
    url"/processor/process.homeshowcase.php"
                
    datadataString,
                
    success:function(response){
                var 
    myArray = $.parseJSON(response);
                var 
    htmldata ='';
            
                
                for (var 
    0myArray.lengthi++) 
                    {
                        var 
    obj myArray[i];
                        
                            
    htmldata=htmldata+'<div class ="itemWrapper well span12 " id="'+obj.id+'"><form class="items" id="'+obj.id+'" action="" method="post">Season Name:<br/><input type="content_txt" value="'+obj.title+'" class="videoName" ><br>Description:<br/><textarea  class="description span5"  rows="5">'+obj.content+'</textarea ><br><input class="videosubmit" id="up_'+obj.id+'"type="button" value="Update" ><input class="delBtn" id="del_'+obj.id+'" type="button" value="delete" ></form><div class="showcaseItem"><img src="'+obj.location+'"height="180" width="320"><input type="file" class="button" multiple></div></div>';
                        
                    }

                  
                        $(
    "#responseWrapper").append(htmldata);
    },
    error:function (){
                    
    alert("Insert a valid playlist Id");
                }
                });    
    }) 

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Which version of jQuery are you using?

    - .click() can only work after appending the element(s)
    - .live() has been deprecated since version 1.7 and removed in version 1.9
    - the solution is .on()
    Code:
    $('SelectorOfExistingParentElement').on('click', 'SelectorOfYourAppendedElement', function() {
       // your code here
    });
    
    // Example: bind a click handler to a (not yet existing) element with id="newelement"
    $(document).on('click', '#newelement', function() {
       // your code here
    });


  •  

    Posting Permissions

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