Overwriting entire html page when calling function


#1


I want my paragraph tags to remain where they are on the page after clicking my button. When I click it now, it erases everything on the page and only document.writes what the functions says.
How can I pretend the page from refreshing?


<!DOCTYPE html>
<html>
<head>
	<title>I don't know</title>
</head>
<body>

	<p>Do you want to play Rock Paper Scissors?</p>

	<button name="data" type="button" onclick="yes()">Yes</button>
	<input type="button" onclick="no()" value="No">

	<script>

		function yes() {
			document.write("Awesome").innerHTML;
		}

	</script>

</body>
</html>


#2

I think you might be posting in the wrong place. This is JavaScript, but you posted HTML. :stuck_out_tongue:


#3

add a <p> tag inside <body> give it an id
like
<p id="demo"></p>

and inside the yes function instead of

document.write("Awesome").innerHTML;

use

document.getElementById("demo").innerHTML = "Awesome";


#4

Oops sorry :frowning: This is my first time posting
Edit: Actually, the lesson I'm trying to do is in javascript lessons, and I have some js code in my html.
I didn't know if I needed to code using html or js to fix my problem, so I just put it here


#5

Ohhh okay, I see now. Thanks a lot :slight_smile:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.