I’m attempting to reverse the order of change events on a particular element:
<!-- HTML-->
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div id='button' style='width:40px;height:40px;background-color:red;'></div>
</body>
</html>
Here is the javascript with the html:
$(function(){
$("#button").bind(‘click’,first);
$("#button").bind(‘click’,second);
$("#button").bind(‘click’,third);
var clicks = $.data('#button', 'events').click.slice();
var button = $('#button').unbind('click');
$.each(clicks.reverse(), function() {
button.click(this);
});
});
function first() { alert(“first”); };
function second() { alert(“second”); };
function third() { alert(“third”); };
This should fire the events in reverse: ‘third’, ‘second’, ‘first’.
When the button is clicked the line:
var clicks = $.data('#button', 'events').click.slice();
produces the error
Uncaught TypeError: $(…).data(…) is undefined.
Can someone please offer a correction to this code which will enable it to run on Firefox.