There is a js (jquery) script with an event function to push elements with id = 'foo'! The script works fine, if the button with id = 'foo' is registered in html. But if we need to add elements dynamically by jquery.append with the same id = 'foo', then the script will not work on their pressing, only on static written in html. How to be? What can be done so that js can work on newly appeared elements?
$(document).ready(function($) { $( "#slim" ).click(function(event) { alert('test ok'); }); $( "#slimgen" ).click(function(event) { $("#boo").append('<input type="button" value="slim" id="slim"/>'); }); }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input type="button" value="generate" id="slimgen"/> <div id="boo"> <input type="button" value="slim" id="slim"/> </div>
onclickcurrent email address - InDevX$(document).on('click', '.another-class', function() {- always saves. If you have an#slimelement, then why are you adding the same? - Rustam Gimranov