1

I have html div which loads empty when the page is first loaded. After that I can click a button which will load fresh html into the div using jquery ajax

$("#control-list a#ms").click(function(){
    var postData = "actionrequest=ms";
    $.ajax({url:"SSSutility.php", type:"post", data:postData, success:function(dataset){
        $("#data-area").html(dataset);
    }});
});

This html has additional buttons inside it when I want to target. Because the JS script is loaded with the original HTML page it cannot target this new html without reloading the JS file that contains the script for the inner buttons. What I'm trying to do is find a way to not have to reload the script in the html response. So far I can only find code which targets the AJAX response on the way in and then triggers a method to run. I need to be able to target the new HTML from a separate method so it is tied to the button clicks.

1 Answer 1

1

This will allow you to target dynamically created buttons by applying the event listener to the document:

$(document).on('click', '#btnId', function(){

});

See jQuery .on() documentation: http://api.jquery.com/on/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.