I know my question has been asked many times but when trying the most common solution that I've seen from multiple stackoverflow answers, I couldn't get it to work. As an example: Why is this jQuery click function not working?. Perhaps I'm missing something fundamental?
Can someone explain why given the following html,
<button id="test1">Create</button>
The following javascript does not fire the button click,
option1
$(document).ready(function(){
$("#test1").click(function(){
console.log("TEST1");
});
});
but the javascript below does?
option2
$(document).on("click","#test1",function(){
console.log("TEST123")
})
If anything I thought option1
would work because it waits for the document to be ready, but instead option1
doesn't and option2
does. Why is that the case? Thank you.