0

Here, I want to have both dynamic div and dynamic button associated with together, should work. I have tried lot of approaches, but I couldn't get what come wrong here. Below is function that I have used for my code. Please help me.

$(function(){
  var count = 0;
  $("#dygraphchartbutton").click(function(event){
    var formURL = "<%=request.getContextPath()%>/DygraphPlot";
    //event.preventDefault();
    console.log("Submitting Data");
    var formData=$("#history_form").serialize();
    console.log(formData);

    $.ajax({
      type:'post',
      url:formURL,
      data:$("#history_form").serialize(),
      success: function(data){
        //alert(data);
        //var str=JSON.parse(data);
        console.log(data);
        appendStr=data;
        $("")       
        $("#report").append("<div id = 'dyplot"+count+"' style = \"float:left;z-index:1;\">"+appendStr+"<br><button onclick='showFullScreen()' id = 'fs"+count+"'>FullScreen</button><button onclick='exitFullScreen()' id = 'nfs"+count+"'>Exit</button></div>");  
        mainDiv = $("#dyplot"+count);
        count++;
      }
    });
  });
});

//display 
function showFullScreen() {
  mainDiv.addClass("fullscreen");       
  $('#fs0').show();
  $('#nfs0').show();
}
function exitFullScreen() {
  mainDiv.removeClass("fullscreen");    
  $('#nfs0').show();
  $('#fs0').show();
}
DaniP
  • 37,813
  • 8
  • 65
  • 74

1 Answers1

0

Jquery on can be used in the following way to interact with elements that are not presented on the page from the beginning (added later dynamically):

jQuery("body").on("click", "#your_new_element", function() {
// your code
});

The clicks will be intercepted and treated on the body element. Have you already tried this?

curveball
  • 4,320
  • 15
  • 39
  • 49