in my project i want to add programmatically certain elements buttons
,because every time a new button
is added , The call is doubled to the same function for the oldbutton
.
var btnElem ='<button type="button"class="doSomething">Button</button><br>';
function ActiveFunc(){
$('.doSomething').on('click',function(){
alert('Clicked');
});
}
$('#Add_Btn').on('click',function(){
$('#div_').append(btnElem);
ActiveFunc();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="Add_Btn">AddBtn</button><br>
<div id="div_"></div>
I want to disable this repeated call to the function , I want to make all the buttons call the function only once , any idea ?
nb: the direct delaration of function is not working for the buttons added programmatically.