I have a button with a onclick attribute which is pointing to the function test()
.
<button onclick="test()">Button 1</button>
<button onclick="test()">Button 2</button>
<button onclick="test()">Button 3</button>
Function test():
function test()
{
var button_name = this.html;
console.log("Im button "+ button_name);
}
How can I get informations about the clicked button? e.g. How can i read the html?
jsfiddle: https://jsfiddle.net/c2sc9j9e/
Pass the this
reference to the function, then read textContent
property the text content of the node.
HTML
<button onclick="test(this)">Button 1</button>
Script
function test(elem){
var button_name = elem.textContent;
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加