Htmlly Htmlly - 7 months ago 37
Javascript Question

How to make text change upon user action?

How would I go about changing a

when the user clicks on an area?

I have my
, which has rectangular areas. Underneath the
is a
. Depending on which area has been clicked, I would like the text itself to change, like from 'change me' to 'i have changed'.

I want to change a paragraph text when user clicks on an element.

Thank you!! :D

Answer Source

let's assume that you have this HTML paragraph:

<p id="paragraph">change me</p>
<button id="btn" onclick="changeP()">Click here to change</button>

You need to make a Javascript function(changeP) as:

function changeP(){
document.getElementById("paragraph").innerHTML = "I have changed";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download