So i have a code tag
<code class="language-html" id="highlighting-content">
</code>
I wanted to change the content inside the tag using Javascript, is there any way to do so?
So i have a code tag
<code class="language-html" id="highlighting-content">
</code>
I wanted to change the content inside the tag using Javascript, is there any way to do so?
code
tag is like other html
tags, below snippet is just to show an example:
function updateCode(){
const radnomNum = Math.random();
const codeEl = document.getElementById('highlighting-content');
codeEl.innerText= radnomNum;
}
document.getElementById('btn').addEventListener('click' , updateCode);
code {
color: crimson;
background-color: #f1f1f1;
padding:5px
}
<div>The rando num:<code class="language-html" id="highlighting-content">no-num</code></div>
<button id="btn" >update code</button>