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.
How I fixed
i solved this issue using:
$('span#load-dots').get(0).innerHTML;
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.
How I fixed
i solved this issue using:
$('span#load-dots').get(0).innerHTML;
Share
Improve this question
edited Nov 23, 2016 at 12:50
Natanael
asked Nov 23, 2016 at 12:34
NatanaelNatanael
3991 gold badge3 silver badges14 bronze badges
5
-
1
There is a type
innterHTML
it should beinnerHTML
. Please clarify if this is code type or just so question type. – Subir Kumar Sao Commented Nov 23, 2016 at 12:35 - 1 Sorry, I was a type error here in Stackkoverflow, I already have edit. – Natanael Commented Nov 23, 2016 at 12:37
-
1
The actual syntax for jQuery is just
html()
– Subir Kumar Sao Commented Nov 23, 2016 at 12:37 -
1
Try
$('#load-dots').get(0).innerHTML
But instead you could use.html
– Rajaprabhu Aravindasamy Commented Nov 23, 2016 at 12:38 - @RajaprabhuAravindasamy the solution with get(0).innerHTML works fine to me, thx :D – Natanael Commented Nov 23, 2016 at 12:48
2 Answers
Reset to default 5innerHTML
works fine:
<p class="load-chart">Carregando Grafico<span id="load-dots">.</span></p>
and
document.getElementById("load-dots").innerHTML = "some new text"
See: .innerHTML - JSFiddle
Also if you are already using jQuery, you should use .html
. Its not a good practice to mix multiple approaches.
.html() - JSFiddle
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
.text() - JSFiddle
Using jQuery one can invoke .html()
,
$('#load-dots').html("any new text");