javascript - jquery keyup dynamically generated div -


this question has answer here:

this java file generates div & text box dynamically.

js file

var count = 6; $(document).ready(function(){     $("#addmoreparam").click(function(){         $("#showparam tr:last").before("<tr><td><div style=\"width:150px;background-color:#fff; height:20px;\" contenteditable=\"true\" class=\"paramdiv\" id="+count+"></div></td><td><input type=text name=\"paramvalue" + count +"\" class=paramvalue /></td></tr>");         count++;     }); }); 

below code produces alert when writing div. tried hard bu not giving alert box.

$(function(){     $(".paramdiv").on('keyup', '.paramdiv', function(){         alert('dd');     }); }); 

i using jquery-1.9.1.js. on supported in jquery version ?

as per event delegation:

event delegation refers process of using event propagation (bubbling) handle events @ higher level in dom element on event originated. allows attach single event listener elements exist or in future. inside event handling function.

issue code is, haven't attached event element exists , in future. #showparam. use

$('#showparam').on('keyup', '.paramdiv', function(){        alert('dd'); }); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -