/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Example of inline event handlers: <input type="text" name="date" onchange="validateDate()" /> This is bad. The purpose of markup is to describe a document's structure, not its programmatic behavior. And what if we need to set handlers for several events on a single element? */ // The unobtrusive solution: <input type="text" name="date" id="date" /> /* A script that runs when page is loaded into the browser, looks for relevant element(s) and set them up accordingly: (using jquery) */ var message = "mouse entered or left."; // passing the variable in by value through eventData: $('#date').bind('mouseenter mouseleave', {msg: message}, function(event) { alert(event.data.msg); });
URL: http://api.jquery.com/bind