has a very long html string, and then I render it to div, and then I take the width of the div. I always get the width before I finish rendering, so the width is not accurate, what should I do?
what"s the solution?
has a very long html string, and then I render it to div, and then I take the width of the div. I always get the width before I finish rendering, so the width is not accurate, what should I do?
what"s the solution?
use setTimeout to get it asynchronously? Or if you are using vue, you can use Vue.nextTick
var div = document.getElementById('example');
var html = [];
for (var i = 0; i < 100000; iPP) {
html.push('<span>' + i + '</span>');
}
$('-sharpexample').html(html.join(' '));
setTimeout(function() {
var width = $('-sharpexample').text().length;
console.log(width);
}, 0);