I think you are looking for an event listener. Things like onblur
, onclick
, onmouseover
, onmouseout
, etc. are not attributes, but rather are inline event listeners that fire when that event occurs.
//select the myElement somehow, either using the element's ID, class, etc.
myElement.addEventListener('focusout', function() {
updateItem(index, row);
hideInputBoxOnElement(row);
});
You can have as many event listeners as you want in an element, so you can even do something like this:
//select the myElement somehow, either using the element's ID, class, etc.
myElement.addEventListener('focusout', function() {
updateItem(index, row);
});
//select the myElement somehow, either using the element's ID, class, etc.
myElement.addEventListener('focusout', function() {
hideInputBoxOnElement(row);
});
Just a suggestion, you might want to use the blur
event instead of the focusout
event. What's the difference, you ask? In web browsers, what's the difference between onblur and onfocusout?
Basically, focusout
is triggered when the element itself or any of its children lose focus, whereas blur
only fires for the element itself.
It is often said that javascript event listeners that don't begin with the prefix on-
is considered a better practice compared to starting with the prefix on-
, but I personally don't think it makes much of a difference.