For example:
document.addEventListener("click", function(e) { if (e.target.id == 'rect') console.log(e.target.value); })
<body> <button type="button" class="rect" id="rect" value="316">5445</button> </body>
PS: I clicked on the document, you better attach it to the element in which your button will appear
Here is an example with your comment code:
var fox = document.querySelector("body"); setTimeout(function() { fox.innerHTML += '<button type="button" class="rect" id="rect" value="316">5445</button>'; }, 2000); fox.addEventListener("click", function(e) { console.log(e.target); if (e.target.id == 'rect') alert(4); });
<body> </body>