Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Click event is not working in html DOM innerTEXT

I want to make a truth or dare website where people can play truth or dare online but I’ve faced some problems.

Html Code

<button id="truth"> +t </button>
<div><p id="game">+t for English Truth, +d For English Dare, +tb For Bangla Truth, +db for Bangla Dare</p></div>

here is my js code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const t = [
    "If you could be invisible, what is the first thing you would do?", 
    "What is a secret you kept from your parents?", 
    "What is the most embarrassing music you listen to?", 
    "What is one thing you wish you could change about yourself?",
    "Who is your secret crush?",
];
document.getElementById('truth').addEventListener('click', function(){
    const truth = t[Math.floor(Math.random() * t.length)];
 const games = document.getElementById('game');
 console.log(truth)
    games.innerText(truth)
})

but when I clicked the button it says Uncaught TypeError: games.innerText is not a function

now, what can I do?

>Solution :

it says that games.innerText is not a function that takes a parameter. The right use of innerText method is:


games.innerText = truth;

same as innerHtml

take a look innerText docs from MDN

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading