我正在尝试获取 innerText
元素的但它返回 undefined
.
代码:
<td id="some-id"><obs conceptId="3156" style="textarea"/>(this one here inserts the span element)</td>
运行时生成的html:
<td id="some-id"><span class="value">14</span></td>
我尝试过使用document.getElementById("some-id").innerText
结果是undefined
。
我尝试过使用 document.getElementById("some-id").innerHTML
结果是<span class="value">14</span>
。我想要得到值 14。
最佳答案
Demo Fiddle
Javascript
var td = document.getElementById('some-id');
alert(td.getElementsByTagName('span')[0].innerHTML);
您关于 innerText
的问题它仅在 IE 中有效,据我所知 Firefox 和 Chrome 使用 textContent
希望有帮助..!!
关于javascript - 当运行时提供元素时,如何在 javascript 中获取innerText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23950447/