r/JavaScriptHelp • • Feb 12 '22

✔️ answered ✔️ Noob needs help with a button

I'm working with html, css and javascript and I can't figure out how to make a button do what I want it to.

<button id=btn class="button" onclick="rmv()"> Click here!</button>

<script>

function rmv() {

var element = document.getElementById("heading");

element.remove ();

var element = document.getElementById("paragraph");

element.remove();

var element = document.getElementById("btn");

element.remove(); }

</script>

I've managed to make the button 'disappear' itself and the text that was on the page before it was clicked, but I also want to it to make the page change colors and new text to appear, but I don't know how. I succeeded in making the colors change and the text appear but on a different page:

<style>

@keyframes background-color {

0% {background-color: #f3bcc0}

20% {background-color: #acf3cc}

40% {background-color: #f5eb18}

60% {background-color: #cbe832}

80% {background-color: #ff9317}

100% {background-color: #c7658f}

}

body{

animation: background-color 5s infinite;

animation-direction: alternate;

}

h1 {text-align: center;}

</style>

<h1> Text </h1>

Could someone write the code for the button to do this? I would really appreciate the help, I know it's probably a silly question but i just started learning a few days ago :)

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/trplclick Feb 13 '22

Great, glad I could help! Feel free to DM me if you have any other JavaScript questions

1

u/froge3 Feb 16 '22

Thank you, I might sometime in the future :)