javascript - Add input box to div on click .html -


i have simple jquery script setup add input box div when div clicked. problem is, when click in input box add text, thinks i'm clicking on div again , try's add input box again, not letting me add text.

$(".match").click(function() {     var match_id = $(this).find(".match_id").text();     $(this).find("#bet").html("<div><input type='text'></div>"); }); 

any ideas how fix it?

the problem input in div. need stop click event propagating div.

try adding this:

$('.match input').click(function(e) {     e.stoppropagation();     e.cancelbubble = true; }); 

or, if want 1 input ever added div, can change event listener this:

$('.match').one('click', function() {     ... }); 

one() execute event listener , remove element, execute maximum of once each matched element.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -