JSFiddle - React, Tailwind, and code Playground
HTML
<button>Add Click handlers from data</button>
<a href="#" onclick="alert('foo')"> Link 1</a>
JavaScript
var onClickVal = $('a').attr('onclick').replace('foo', 'bar')
$('<a href="#"></a>').attr('onclick', onClickVal).text('Link 2').appendTo('body')
/* remove and store existing "onclick" */
$('a').each(function() {
var onclick = $(this).attr('onclick')
$(this).data('oldClick', onclick)
$(this).removeAttr('onclick')
})
$('button').click(function() {
$('a').click(function() {
eval($(this).data('oldClick'))
})
})