Hello wonderful people at Stack Overflow,
I've been attempting to create a table generator that dynamically creates two tables upon the click of a button. So far, it's been quite a frustrating journey full of roadblocks...
Currently, my approach involves generating a <p>
element with a class of "heading" and a <div>
element with a class of "content". The idea is that when the p
element is clicked, the content will slideToggle.
I've tried using on()
with jQuery and attaching various functions to the p
element, but none seem to be working as expected. Additionally, the use of .hide()
on the content doesn't seem to do anything, which is incredibly frustrating. Any guidance or advice on how to tackle this issue would be greatly appreciated!
The event handler seems to work fine for content that I've hardcoded in the HTML, but not for AJAX-generated code that gets appended to the div.
Here are some snippets of the relevant code: Ajax:
function submition() {
$.ajax({
type: 'GET',
url: 'phpQueries.php?q=getQueryBuilder&schools=' + mySchools.toString()+ '&depts=' + myDeps.toString() + '&lvls=' + myLevs.toString() + '&srcs='+mySrc.toString() + '&codes='+myCodes.toString(),
success: function (data) {
$("#dump_here").append(data);
}
});
jquery:
$(".heading").on("click", function() {
alert("Hello World");
$(this).next(".content").slideToggle(500);
});
PHP:
echo '<p class="heading">See/Hide Comments</p> ';
echo '<div class="content">I am I am I am.... Superman!</div>';
Warm regards, Gempio