EN
JavaScript - can I set text inside node using setAttribute?
1 answers
3 points
Can I set the text inside text node using setAttribute
?
This doesn't work:
xxxxxxxxxx
1
2
<html>
3
<body>
4
<div id="my-div"></div>
5
<script>
6
var myDiv = document.querySelector('#my-div');
7
myDiv.setAttribute('textContent', 'Some text...');
8
</script>
9
</body>
10
</html>
1 answer
3 points
No, you can't. Use the following solution:
xxxxxxxxxx
1
myDiv.textContent = 'Example text...';
Note:
Check alternative solutions and runnable examples here:
0 commentsShow commentsAdd comment