user1943442
user1943442

Reputation: 198

Reloading jQuery after AJAX Div Load

I used ajax to load some code I have in php

function loadNewcomment(divID) {
$.ajax({
        url: templateUrl+"/enternote.php",
        cache: false,
        success: function(html){
            $("#"+divID).append(html);

        }
    });
}

And I have this code within $(document).ready(function(){ }); but it doesn't detect the new DIVs, how can I re-load that part of the code?

$keyPressed = 0;
    $(".note-field").keyup(function(event){
        var thisString = $(this).val();
        $keyLength = thisString.length;
        $rowCount = Math.ceil($keyLength/40);
        $currentRow = $(this).attr("rows");

        if($currentRow < $rowCount){
            $(this).animate({rows:$rowCount},50);
       }

Upvotes: 0

Views: 781

Answers (1)

dsgriffin
dsgriffin

Reputation: 68566

You'll need event delegation in this case.

Replace

$(".note-field").keyup(function(event){

With

$(document).on('keyup', '.note-field', function(event){

Upvotes: 2

Related Questions