Get element from which onclick function is called

前端 未结 8 875
野趣味
野趣味 2021-01-18 03:59

I have a button with a onclick attribute which is pointing to the function test().


<         


        
8条回答
  •  [愿得一人]
    2021-01-18 04:50

    Pass the this reference to the function, then read textContent property the text content of the node.

    HTML

    
    

    Script

    function test(elem){
       var button_name = elem.textContent;
    }
    

    Fiddle

提交回复
热议问题