Ask coding questions

← Back to all posts
How to make interaction in HTML,CSS,JS
Trex10 (7)

How do I make it so that if a user clicks something on the HTML page it changes something on there? I know I can do a function event listener thingy in the JS. But it than just changes it to a blank page with whatever I want. Is there a way to make it so when I put something on the screen its on the same backgound and text?

Comments
hotnewtop
[deleted]

Invite me to the repl I’ll show you

Trex10 (7)

@IL2PG
Ok, did you get the invite?

[deleted]

@Trex10 no. Try using invite link

[deleted]

@Trex10 I’m in

Coder100 (17018)

Html:

<p id="demo">lol</p>
   <button id="button">Clikc </button>

js:

document.getElementById("button").addEventListener("click", function() {
  document.getElementById("demo").innerHTML = "Paragraph changed!";
});

perhaps you need to take the time to properly learn js?

Trex10 (7)

@Coder100
IL2PG is helping me that wasn't as it started

Trex10 (7)

@Coder100
I first looked at @DavidShen2 s link and put that there but than @IL2PG Started helping me and that stayed there.

DavidShen2 (60)

You can use javascript to change the HTML.
More info here: https://www.w3schools.com/jsref/prop_html_innerhtml.asp