Jquery Event Chaining
Solution 1:
I think you are looking for bind. Bind can wire multiple events to the same function using a single call instead of using a chain:
$("textarea.checkMax").bind("keyup mouseover", checkMaxLength);
Solution 2:
Anything that returns the jQuery object can be used to chain. In general, everything returns the jQuery object, so if the API doesn't explicitly say it doesn't, chances are that the particular method does return the jQuery object and can be chained.
In the case of events, yes, they do return the jQuery object and can thus be chained. See Here
In your case, you can make an external function that takes one parameter, the object that the event happened on, and then check the length of it, or whatever else you want to do. Then, you just call mouseUp(myFunction).mouseOut(myFunction).keyPress(myFunction)
or whatever else you were looking to chain together.
Here is a more explicit example:
<scriptlanguage="javascript"type="text/javascript">
$(document).ready( function () {
setMaxLength();
$("textarea.checkMax").keyup(checkMaxLength()).
mouseover(checkMaxLength(this.id));
});
</script>
Post a Comment for "Jquery Event Chaining"