How do i get the text inside a with button with clicking on it, with Javascript?

Viewed 1364

i need the result in a html paragraph

<p id="result">Here the Button Text</p>

This is the Html part

<button type="button" id="vteam">i need this text</button>

This is the JS part

$(document).on('click', '.vteam', function(event) {}

2 Answers

event.target refers to the clicked element, so you can get the text inside it like so: event.target.innerText.

I think you can use the following:

    function changeText() {
        document.getElementById("vteam").innerHTML = "Hello";
}

and

<p id="vteam" onclick="changeText()">I need this text to change</p>
Related