Every couple of seconds on the server I generate a chunk of html, which I display in UI by using jQuery method .html().
$('#contentContainer').html(JSON.parse(htmlString));
Injected html is correctly displayed.
However, there are also some javascript functions, which manipulate this html code. For example, one is connected to the div element:
$("#startStop").click(function () { ..});
Another to bootstrap tooltip:
$(function () {
$("[rel='tooltip']").tooltip();
$(".errorTip").tooltip();
});
The problem is that they no longer work when I populate the div element with the html from the server.
I can see that the elements are created with correct ids:
<div id="startStop" data-toggle="button" class="sbClickable btn active">
....
</div>
The only difference, is that when I open the source code in chrome, the generated html is missing there.
Here are the steps, how I load code to the page:
- page.chtml file is loaded
in the page.chtml there is an empty div
<div id="contentContainer"> </div>then in page.chtml I call a method to populate the container. The method is located in external .js file
<script type="text/javascript"> einzelaktion.populateHtml(); </script>in populateHtml I make an ajax request to the server. When data is retrieved I empty the div and populate it with the new data:
$('#contentContainer div').empty(); $('#contentContainer').html(JSON.parse(htmlString));Methods, with which I have problems located in the same external .js file.
I tried moving method, which populates the container, to page.chtml, but it didn't help.
I also tried to create container elements when page is loaded in a straightforward manner, so they are created together with other elements for page.chtml and they are visible in the page source. In this case, everything works correctly till I make a first call to server and replace the html for the div.
I googled similar problems, but didn't find anything close to my issue..
Do I miss something?