I'm using 1.7.2 in which I understand this should work:
// cell is a jquery representation of a <td> element
cell.append($("<input/>", { "type": "text" }).val(content));
cell.children()[0].focus();
cell.children()[0].on("blur", function() {
alert("blur");
}
The input box is appended, grabs focus and then the javascript console tells me:
Uncaught TypeError: Object #<HTMLInputElement> has no method 'on'
I'd be grateful if anyone knows how I can catch the blur/focusout event.
The blur event fires when an element has lost focus. The main difference between this event and focusout is that focusout bubbles while blur does not. The opposite of blur is focus . This event is not cancelable and does not bubble.
The main difference between this event and blur is that focusout bubbles while blur does not. The opposite of focusout is focusin .
jQuery blur() Method The blur event occurs when an element loses focus. The blur() method triggers the blur event, or attaches a function to run when a blur event occurs. Tip: This method is often used together with the focus() method.
blur() method removes keyboard focus from the current element.
You are accessing the DOM element with [0]
and acting like it is a jQuery object.
If you only want the first, you need to use eq()
to get the jQuery object.
cell.children().eq(0).focus().on("blur", function() {
alert("blur");
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With