Working on a snippet that just doesn't work. Backticks used to write html textareas while in the JS script.
May sound weird but I would really like to know where I've gone wrong after hours of work. Alert should show the result.
May sound weird but I would really like to know where I've gone wrong after hours of work. Alert should show the result.
Code:
<script>
var item="red"; // (for testing)
function doit(){
var elements=document.getElementsByClassName(item).value;
var found=elements[0];
alert(found); // text in left box (red);
}
document.write(`<textarea class ="${item}">red</textarea>`);
document.write(`<textarea class ="${item}">blue</textarea>`);
document.write('<button onclick ="doit()">CLICK</button>');
</script>