I’m having some problems binding to the keyup event of a textarea control. I’m trying the below
var shortDescInput = $('nobr:contains("Short Description")').closest('tr').find($('textarea[title="Short Description"]'));
// this doesn't work
shortDescInput.bind('keyup', function () {
countShortDescChars();
});
// Nor this
shortDescInput.keyup(function () {
countShortDescChars();
});
Am I missing something here that’s really obvious? This is working for other controls, for example binding events to radiobuttons. I’ve checked and I’m defiantly selecting the right textarea with
var shortDescInput = $('nobr:contains("Short Description")').closest('tr').find($('textarea[title="Short Description"]'));
I just never seem to get the keyup event….
find($('textarea[title="Short Description"]'))is highly inefficient. For your purposes,findshould take a selector as it’s argument.When you pass in a jQuery object to
find, jQuery first queries the DOM from the top and finds all elements that match that selector. Then,findloops through all of these results until it finds one that matches the specified parents.You should, instead, use:
Also, use
.oninstead of.bind..bindis set to be deprecated in future releases for it’s inefficiency.And the revised code: