i have try different solutions from this media but still it does not work for me please help me.
function get_category(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var ans = document.getElementById("sell_panel");
ans.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "includes/get_category.php", true);
xmlhttp.send();
}
`$('.item_btn').on('click', function () {// HERE IS MY CLICK EVENT
alert("helo");
});`
AND MY get_category.PHP FILE IS;
<?php
include("database.php");
$db = new Database();
$sql = "SELECT DISTINCT category FROM stock";
$result = mysql_query($sql);
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
while($cat = mysql_fetch_array($result)){
echo "
<div class='item_btn' id='{$cat[0]}'>//HERE IS THE DIV
<label>{$cat[0]}</label>
</div>
";
}
?>
I HAVE TRIED delegate() also it did not work for me and i have heard about to trigger my event handler in ajax but i dont know how to do it please help me guys