You can bind handlers to all kinds of events on non-input elements (click
, mousemove
, etc.). But there is no (consistent cross-browser) event raised when an attribute changes (such as your example of an href
attribute on a link). Some attributes (like src
) will cause an event (like load
) as a secondary thing, as bfavarello pointed out.
(There's a now-dead proposal for "mutation" events on elements, including attribute changes [mutations], but it was never broadly supported. There's a newer proposal, but it is also not [yet] broadly supported.)
You can, of course, use polling: Save the old value, and check back periodically (via setTimeout
or setInterval
) to see if it has changed. Unless you're checking a lot of elements and need to check them near-constantly, this needn't be a performance problem.