kvess kvess - 1 month ago 6x
Ajax Question

jquery add toggle function to div after adding html to it

Good day every one. How can I add toggle function to a div which is populated with ajax response on click. Right now i can achieve the both functions but I need two clicks to get the div displayed after getting populated. Can I get this done at one click (i.e populating the div and adding toggle function)?

Any help would be greatly appreciated. Thanks in advance. Good be with all.

My code:

$(".ex2").on('click', '.spnSelected', function() {
var self = $(this).closest("tr");
var col1_value = self.find(".col1").text();
type: 'GET',
url: 'reportForm.php',
data: { propid: col1_value },
success: function(response) {


Second line $(".ex2").on('click', '.spnSelected', function() { change to $("body").on('click', '.ex2 .spnSelected', function() { should work like charm.

in you code you attached event on .ex2 click, so if you adding more .ex2 elements with ajax. you don't have event attached on new elements. when you attact click event on body and then check if .spnSelected clicked this shuld work with new elements.