Home > Enterprise >  Click event is not working in html DOM innerTEXT
Click event is not working in html DOM innerTEXT

Time:11-23

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

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?

CodePudding user response:

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

  • Related