on click not working on dynamically created element


As i know and understand that for dynamically created element, we need to write jquery function like

//.class is a element which is added dynamically in page using ajax call
$(".Class").on('click',function(){
//Code to execute here
alert("in here"); //not able to call it


})

but when i am trying to do it, i am not able to call this function.
Am i doing this correctly or something is wrong?

 


Asked by:- jaya
2
: 334 At:- 6/4/2017 11:16:10 AM
jquery dynamic created element






1 Answers
profileImage Answered by:- jaiprakash

ok, i have faced this issue, and i can solve your problem quickly

you need to write function like this

//.class is a element which is added dynamically in page using ajax call?
$(document).on('click',".Class",function(){?
//Code to execute here?
alert("in here");· //not able to call it?

});


//that's it you are done

Important points

  $("element") element must be loaded with page, means instead of document in above code you can replace it with any element id, which is loaded with page, and should be parent of dynamically added element(that is ".class" here)

2
At:- 6/4/2017 11:41:16 AM
ok thank you , got it, it is working now 0
By : jaya - at :- 6/4/2017 11:43:46 AM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use