Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy Onclick event of an element

hi to all i have an interesting question

is it possible to copy onclick event of an element like this

$('#ElementId').attr('OldOnClick',$('#ElementId').attr('OnClick'));

Please guide me if there is any way of doing this.

i am trying to disable click event of all elements present on form at some point and on some other point i have to recover them so i am trying to save their onclick with other attribute name

like image 475
rahul Avatar asked Jan 16 '23 06:01

rahul


1 Answers

yes, you can access handler functions. The way of doing it in jquery would be this:

$('#specialbutton').click(function(){ console.log("peaches");};

var handlerFunction = $('#specialbutton').data("events").click[0].handler;

$('#specialbutton').click(); // "peaches"
handlerFunction(); // "peaches"

you would then assign it to another element like this:

$('#otherelement').click(handlerFunction);
$('#otherelement').click(); // "peaches"
like image 126
ChuckE Avatar answered Jan 25 '23 20:01

ChuckE