没有jQuery更改元素文本? [英] Change element text without jQuery?
本文介绍了没有jQuery更改元素文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在不使用jQuery的情况下更改div的内容。我想按ID或类选择div。
I am trying to change the contents of a div without using jQuery. I want to select the div by id or class.
我设法得到了附加工作:
Ive managed to get append to work:
function appendHtml(targetC, htmldata) {
var theDiv = document.getElementById(targetC);
var newNode = document.createElement('div');
newNode.innerHTML = htmldata;
theDiv.appendChild(newNode)
}
但是无法弄清楚如何改变一个文本..
But cant figure out how to change text of one..
任何想法?
推荐答案
参见这个小提琴基本样本
<html>
<head>
<script>
function bold(targetC) {
var theDiv = document.getElementById(targetC);
theDiv.innerHTML = '<b>' + theDiv.innerHTML + '</b>';
}
</script>
</head>
<body onload='bold("message")'>
<div>Hello, World!</div>
<div id="message">What a nice day!</div>
</body>
</html>
这篇关于没有jQuery更改元素文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文