1

how are you guys I have a question if anyone can help me, I'll be grateful.

at the moment I was using some bootstrap functionality, for example, this code below. I'm using bootstrap version 3

<div class="col-lg-12 col-md-12 col-xs-12  div_challenger" style="background-color: #somecolor; color:someTextColor;"
    data-toggle="tooltip" data-placement="right" title="some text here!!!">
    <span class="some icon"></span>
    <b>some title</b>
    <input type="hidden" value="somevalue" name="inputChallengerSelected">
</div>

this code works well in html file. But when I use Jquery append element this doesn't work the same way

code using jquery append.

<button id="someid" onclick="addElement()"> ADD element </button>
<div id="addhere"> </div>

script tags

<script>
function addElement(){
   let ElementToAdd = `    <div class="col-lg-12 col-md-12 col-xs-12  div_challenger" style="background-color: #somecolor; color:someTextColor;"
    data-toggle="tooltip" data-placement="right" title="some text here!!!">
    <span class="some icon"></span>
    <b>some title</b>
    <input type="hidden" value="somevalue" name="inputChallengerSelected">
</div>`
 $('#addhere').append(ElementToAdd)
}

if someone tells me why this occurs I will be totally grateful

vronjec
  • 259
  • 1
  • 13

2 Answers2

1

Take a look at this: How to bind bootstrap tooltip on dynamic elements

In order to make a dynamically injected tooltip work, you must initialize a tooltip plugin using an element, which exists already after the page is loaded, e.g. body. It should then work.

kwiat1990
  • 479
  • 1
  • 5
  • 12
0

A simple answer is Bootstrap = CSS + JS. Try to hide element onload and when you need show.

stefo91
  • 618
  • 6
  • 16