I have the next chunk of html on my html doc:
<p class="load-chart">Carregando Grafico<span id="load-dots">.</span></p>
When I try to use innerHTML on I get the undefined msg, however when I use:
$('#load-dots').text("any new text");
it works fine.
i solved this issue using:
$('span#load-dots').get(0).innerHTML;
innerHTML
works fine:
<p class="load-chart">Carregando Grafico<span id="load-dots">.</span></p>
and
document.getElementById("load-dots").innerHTML = "some new text"
Also if you are already using jQuery, you should use .html
. Its not a good practice to mix multiple approaches.
Also note that .html
or .innerHTML
is used to update markup of an element. If you just wish to update text, use .text()
. Pure JS alternative would be .textContent
使用.html()
,
$('#load-dots').html("any new text");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.