Q:

turning inline onClick event on off

I'm doing some validation where i need to turn off inline onClick event and then turn it on.
Jquery on off method does't work for inline onClick event. The line below removes the onClick event. Before this I'm saving event into an array 
$('.elements a').prop('onclick',null).on('click');

Saving events into array
    var arr = [];
    var i = 0;
     $('.elements a').each(function(){
        arr[i++] = $(this).attr('onclick');
       });

How can I reassign these events in same order to each element. Hope it can be added using addEventListener ?
Or is there any other way to achieve the same ?

A:

Since you have to use inline events handlers, you can store removed attributes in array and then just reset them back:

var events = $('.elements a').map(function() {
    var onclick = $(this).attr('onclick');
    $(this).removeAttr('onclick');
    return onclick;
}).get();


// ... Apply events later
$('.reset').click(function() {
    $('.elements a').each(function(i) {
     $(this).attr('onclick', events[i])
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="elements">
    <a href="#" onclick="console.log(1)">Link 1</a>
    <a href="#" onclick="console.log(2)">Link 2</a>
    <a href="#" onclick="console.log(3)">Link 3</a>
</div>

<button class="reset">Reset events</button>

