I have a button which triggers a popover. It is generated by another script.
$('#appendTarget').append('<div class="col-md-3" style="border: 2px solid grey; border-radius: 12px; padding: 5px; margin-bottom: 10px;">' + item.name +
'</div>' +
'<div class="col-md-3"><button class="btn" style="margin-bottom: 10px" onclick="showPopover(this)"><b style="color: red"><img src="Img/gear.png" style="width: 20px; height: 20px"></b></button>');
This is my function for triggering:
function showPopover(element) {
$(element).popover({
html: true,
content: function() {
$('#popover-content').append('<a href="#" class="btn btn-secondary">Edit</a>'
+'<a href="#" class="btn btn-info">Activate</a>'
+'<a href="#" class="btn btn-danger">Delete</a>');
}
});
}
And the popover-content
is this:
<ul id="popover-content" class="list-group" style="display: none">
</ul>
But it is not working. However if I add this links directly into <ul>
it works. But I want to add it dynamically so I can assign the id to each link (button).
Anyone? Why append is not working in this case?
EDIT
@Arex had a good point that display:none
state was not changing. I changed my function and it looks like this:
function showPopover(element) {
$(element).popover({
html: true,
content: function() {
var popover = $('#popover-content');
popover.show();
popover = popover.append('<a href="#" class="btn btn-secondary">Edit</a>'
+'<a href="#" class="btn btn-info">Activate</a>'
+'<a href="#" class="btn btn-danger">Delete</a>');
return popover;
}
});
}
And it works but very strange...
When I click first time it looks like everything is fine:
After that when I try to close that popover, it extends (doubles) the content:
And finally when I try to open it again, it shows empty popover :/
EDIT 2
I added popover.empty()
and it works.. But when I open and close popover 2-3 times, it becomes empty. This starts to be annoying -.-
List item 1 List item 2 List item 3
. It is not 'valid' but it will work. – Arex Jun 29 '18 at 09:12