1

I use a sanitize: false configures popover with Bootstrap 5:

<button type="button" 
        class="btn btn-primary btn-sm" 
        data-bs-container="body" 
        data-bs-toggle="popover" 
        title="register"
        data-bs-content="${popoverContent()}">
         <i class="fas fa-server">
</button>

js part:

let popoverContent = function ( ) {
    let buttonsDiv = document.createElement("div")
    let delButton = document.createElement("button");
    delButton.textContent = 'delete';
    buttonsDiv.appendChild(delButton);
    return buttonsDiv.innerHTML;
}

which looks like this:

enter image description here

if I now change the js code to:

let popoverContent = function ( ) {
    let buttonsDiv = document.createElement("div")
    let delButton = document.createElement("button");
    delButton.textContent = 'delete';
    delButton.classList.add('btn');
    buttonsDiv.appendChild(delButton);
    return buttonsDiv.innerHTML;
}

I get this:

Why did not just the button get another class="btn" attribute?

update: This is what the HTML looks in the console after the classList.add('btn'):

<button type="button" 
        class="btn btn-primary btn-sm" 
        data-bs-container="body" 
        data-bs-toggle="popover" 
        data-bs-placement="left" 
        title="" 
        data-bs-content="<button class=" btn"="" 
                                 data-bs-original-title="register on server">delete</button>

obviously class=" btn"="" should be class="btn" - but where is my error?

update: I added a fiddle to show the problem: https://jsfiddle.net/93gLyha2/12/ - also watch how the button changes it size when uncommenting the 2nd or 3rd line in the js part of the fiddle

xtlc
  • 1,070
  • 1
  • 15
  • 41
  • Why are you dumping the button element into a div just to dig it out again? Why not just return the button element? – isherwood Sep 02 '21 at 12:53
  • Also, did you notice that the blue buttons are apparently modified by your script? Or is that not part of the issue? Please put all your code into a single functioning snippet using the editor. Load Bootstrap via CDN. – isherwood Sep 02 '21 at 12:54
  • I added a fiddle to show the display in even simpler way. – xtlc Sep 02 '21 at 14:14

0 Answers0