Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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) {}

like image 269
Marco Patzelt Avatar asked Sep 15 '25 20:09

Marco Patzelt


2 Answers

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

like image 86
Oskar Zanota Avatar answered Sep 18 '25 18:09

Oskar Zanota


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>
like image 39
Lerconn Design Avatar answered Sep 18 '25 18:09

Lerconn Design