Pass Parameters with a setTimeout Function
I struggled for hours to get this to work. Well, here's a functioning example.
by Cerebrl
HTML
<input type="button" title="Hello, world!" value="Says hi in 2 seconds" />
CSS
input {
display: block;
width: 15em;
margin: 50px auto;
padding: 1em 0;
}
JavaScript
$('input').click(function () {
var that = $(this);
setTimeout(function() { alertMsg(that); },2000);
});
function alertMsg(x) {
var message = x.attr('title');
alert(message);
}