I'm trying to add a tooltip to an a tag in my code but it throws an error :Cannot create property 'position' on string

2736 views javascript
0

function apply_glossary(arr) {

  var res_string = document.querySelector(".show-content").innerHTML;

  arr.forEach(function(e) {

    var tooltip_string = "<a style= 'border-bottom: 2px dotted black; color:inherit; text-decoration:none;' data-toggle='tooltip' data-placement='top'  href='#' id='tooltip-link' data-tooltip='" + e.content + "'>" + e.key + "</a>";

    res_string = replaceAll(res_string, e.key, tooltip_string);
  });

  document.querySelector(".show-content").innerHTML = res_string;
  console.log(res_string);


}

$('[data-toggle="tooltip"]').tooltip();
});

answered question

Do you have any HTML to show us properly?

It is just a string with HTML. I dont know what function replaceAll do but you must append that HTML to proper place for ex. with jQuery $(parent).append(res_str)

1 Answer

0

You can't adjust innerHTML by naming it a variable, that gets it. Change this line:

    var res_string = document.querySelector(".show-content").innerHTML;

To this:

    var res_string = document.querySelector(".show-content");

And this line:

res_string = replaceAll(res_string, e.key, tooltip_string);

With this:

res_string.innerHTML = replaceAll(res_string, e.key, tooltip_string);

posted this

Have an answer?

JD

Please login first before posting an answer.