Change events execution order using jQuery.live()
I have the following piece of code:
<html>
<head>
<script src="myplugin.js" />
<script>
$(document).ready(function() {
$('#mytable tbody tr').live('click', function() {
alert('Hi');
});
});
</script>
</head>
<body>
<script>
$('#mytable').myplugin();
</script>
<table id="mytable">
<tbody>
<tr>
<td>Something</td>
</tr>
</tbody>
</table>
</body>
</html>
myplugin.js code
.....
return this.each(function(index, id) {
$(id + ' tbody tr').live('click', function() {
alert('Hello');
});
});
.....
Under that circustances, the order of executiong would be:
alert('Hi');
alert('He开发者_C百科llo');
but I want to be the inverse. It's possible to change the execution order for this? thank you
This is not the prettiest way, but you could postpone your first call like this:
$(document).ready(function() {
$('#mytable tbody tr').live('click', function() {
window.setTimeout(function() {
alert('Hi');
}, 0);
});
});
But maybe there's an "official" way as well...
You should swap the order of the scripts.
精彩评论