Skip to content
Advertisement

focusout event not working for dynamically generated textbox

//<![CDATA[ 
$(window).load(function() {

    $('.n_val').focusout(function() {
        alert(this.id);

    });

});//]]>

To generate textbox dynamically

buffer += "<tr><td>" + nomen_list.getName() + "</td><td><input type='text' style='width:50px' class='n_val' id=" + nomen_list.getId() + "-" + nomen_list.getCat() + " value=" + nomen_list.getVal() + " /></td></tr>";

I getting dynamically textbox, but focusout is not working for dynamically generated textbox, whereas same page has some textbox, which is hard-coded for that, above script gets triggered.

Advertisement

Answer

$(window).load(function() {
    $(document).on('focusout','.n_val',function() {
        alert(this.id);
    });
});

Instead of using document you could use the text box’s closest parent id or class. I have no idea of your html layout, hence using document. Also see jQuery on.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement