0

here is my code in jquery, and i want to get the data in tech-support-bullet-chart2

$.ajax({
    type:"POST",
    url:"includes/bullet-chart.php",
    data:{
        daterange:ym
    }
}).done(function(e){
    var tech_support = JSON.parse(e);
    //console.log(tech_support);
    for(i=0;i<t_s.length;i++){
    //console.log("support:"+tsn + ", complete:" + tsc + " ,Pending:"+ tsp +", isExist:"+isExist);
    $("#div-charts").append('<div class="tech-support-list">'+
    ''+
    '<div class="tech-support-name">'+t_s[i]+'(<label id="i'+t_s[i]+'"></label>)</div><div class="support-charts">'+
    '<div class="tech-support-bullet-chart1" id="'+t_s[i]+'-close">'+
        '</div><div class="spacer"></div>' +
        '<div class="tech-support-bullet-chart2" data-sname="'+t_s[i]+'" id="'+t_s[i]+'-open">' +
        '</div></div></div>');
    }

here is my function in geting the data-sname

$(".tech-support-bullet-chart2").click(function(){
var name = $(this).data("sname");
alert(name);})

and my problem is.. my second code does not working.. please help me on this..

thank you in advance!

1 Answers1

0

Update your code like:

$(document).on("click", ".tech-support-bullet-chart2", function(){
    var name = $(this).data("sname");
    alert(name);
})

This is the event delegation technique to bind event handler to the DOM element which are getting added to DOM after loading of document.

vijayP
  • 11,432
  • 5
  • 25
  • 40