admin管理员组文章数量:1333451
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) {}
-
Example
$('#vteam').on('click', function(e) { $(this).text('text here')})
– Aks Jacoves Commented Sep 5, 2020 at 12:33
3 Answers
Reset to default 6event.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
本文标签: How do i get the text inside a with button with clicking on itwith JavaScriptStack Overflow
版权声明:本文标题:How do i get the text inside a with button with clicking on it, with Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742353579a2458972.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论