最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

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

Share Improve this question edited Sep 5, 2020 at 12:36 Marco Patzelt asked Sep 5, 2020 at 12:31 Marco PatzeltMarco Patzelt 431 silver badge5 bronze badges 1
  • Example $('#vteam').on('click', function(e) { $(this).text('text here')}) – Aks Jacoves Commented Sep 5, 2020 at 12:33
Add a ment  | 

3 Answers 3

Reset to default 6

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>

You can give your inner text as an id to element .and in event handler you can access your inner text by this way:

e.target.id 
发布评论

评论列表(0)

  1. 暂无评论