I've a function with on click method. After clicking an element with a class name, i want to do something. i called that function in document ready. and with jquery append method a dom element is being added with that class name. and i want to call that again to work that function again. but this time function is calling twice. please check below code for understanding.
function function_name() {
$('.selector').on('click',function () {
//do something
console.log('a')
});
}
$(document).ready(function(){
function_name();
});
// after jquery append - a element with selector class is adding in dom.
// this call is inside a ajax call to bind that click with new dom element
function_name();
It's adding 'a' twice in console.
How to prevent this?