Clicking the inbox button triggers the inbox_open() function. When this function runs, three buttons appear in the inbox header but there is no onclick event listener attached to them. Make sure to review the code after the // inbox.open
comment for critical lines:
b.onclick = function() { console.log("button was clicked"); }
and inbox.setAttribute("title", poH.innerHTML);
// inbox
var inbox = document.getElementById("inbox");
var inbox_news = document.getElementById("inbox_news");
var poH = document.createElement("span");
var poC = document.createElement("span");
var new_from_to = [0, 2, 3];
var number_of_news = [2, 1, 2];
var news_price_data = [10, 20, 30, 40, 50];
// inbox.open
function inbox_open() {
for (var i = 0; i < number_of_news.length; i++) {
var b = document.createElement("button");
b.innerHTML = (i + 1);
b.className = "poH";
b.onclick = function() {
console.log("button clicked");
}
poH.appendChild(b);
}
inbox.setAttribute("title", poH.innerHTML);
}
// inbox.addEventListener
inbox.onclick = inbox_open();
// Allow BS 4 popover to run
$(document).ready(function() {
$('[data-toggle="popover"]').popover();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<!-- HTML -->
<button id="inbox" class="btn btn-primary btn-sm" style="float: right; margin: 30px 30px 0 0;" data-toggle="popover" data-placement="left" data-html="true" title="" data-content="">inbox <span id="inbox_news"></span></button>