I've created buttons with javascript, I've added these to HTML. I want to handle these with jQuery. How to get worked to click on b_1 and b_2?
$("#mainbutton").click(function (){
document.getElementById("content").innerHTML = '<button id="b_1">Button1</button><button id="b_2">Button2</button>'
})
$("#b_1").click(function (){
alert("You've clicked button1!");
})
$("#b_2").click(function (){
alert("You've clicked button2!");
})
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<button id="mainbutton">Click me!</button>
<div id="content"></div>
</head>