jQuery - Event for when an attribute of a node changes

若如初见. 提交于 2019-12-01 03:23:25

问题


I have a webpage with an external javascript library, and my own extra code. The external library can't be change. It manipulates dom elements, adds new ones, changes attributes (e.g. src on some <img> nodes, etc.). I am using jQuery. Is there any event handler that is fired when the value of an attribute changes of a node?

i.e. is there anyway I can detect (in jQuery) when the src of an <img> is changed (by someone else?)


回答1:


You can go for the jQuery watch plugin to detect changes in the attributes.

Check out this post too:

http://darcyclarke.me/development/detect-attribute-changes-with-jquery/




回答2:


If you just need to know when the source of an image changes, you just need to add an onload handler to the image. When the image loads, it will fire the event.

$("img").load( function(){ alert('loaded'); } );


来源:https://stackoverflow.com/questions/4179716/jquery-event-for-when-an-attribute-of-a-node-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!