I'm trying create a bootstrap tooltip in a button in javascript.
This is what I'm trying to achieve:
<input type="image" src="~/images/icon_trash_red.png" class="m-l-20" onclick="RemoveItem(this)" height="20" data-toggle="tooltip" data-placement="right" title="Remover aluno" />
This is what I have so far:
button = document.createElement("Input");
button.src = "/images/icon_trash_red.png";
button.width = '20';
button.type = 'image';
button.onclick = function () {
RemoveItem(this);
};
button.style.marginLeft = '70px';
button.title = "Remover aluno";
button.setAttribute("data-toggle", "tooltip");
The 'setAttribute' seems to be working fine, because if I change to something like this: button.setAttribute("height", "50px");
it works.
Any ideas what I'm doing wrong?
I'm trying create a bootstrap tooltip in a button in javascript.
This is what I'm trying to achieve:
<input type="image" src="~/images/icon_trash_red.png" class="m-l-20" onclick="RemoveItem(this)" height="20" data-toggle="tooltip" data-placement="right" title="Remover aluno" />
This is what I have so far:
button = document.createElement("Input");
button.src = "/images/icon_trash_red.png";
button.width = '20';
button.type = 'image';
button.onclick = function () {
RemoveItem(this);
};
button.style.marginLeft = '70px';
button.title = "Remover aluno";
button.setAttribute("data-toggle", "tooltip");
The 'setAttribute' seems to be working fine, because if I change to something like this: button.setAttribute("height", "50px");
it works.
Any ideas what I'm doing wrong?
Share Improve this question edited Apr 3, 2017 at 15:32 gregoryp asked Apr 3, 2017 at 14:49 gregorypgregoryp 1,0195 gold badges18 silver badges39 bronze badges 01 Answer
Reset to default 4It will add the attribute to the element but you need to initialize the tooltip.
// initialize tooltip for all elements which has the data-toggle attribute
$('[data-toggle="tooltip"]').tooltip()
// or initialize just for the button
$(button).tooltip()
Note : The code should be after adding the attribute to the element.