Is there any way to get the value of the onclick? [closed]

-3

In other words, I would like to obtain the value of the onclick="ejemplo" obtain the function of the onclick

    
asked by Josbert Hernandez Riera 10.07.2017 в 15:45
source

2 answers

1

You can do it with getAttribute:

var x = document.querySelector("button").getAttribute("onclick");

Example: link

    
answered by 10.07.2017 в 15:59
0

Use HTML of jquery if you want to get the writing done in a div for example. You have other options, depending on what you refer to as value, as val()

var valor=$('#b').html();

function alertar(){
alert(valor);
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="b" onclick="alertar()">ESTO ES UN DIV</div>
    
answered by 10.07.2017 в 15:55