Is it possible to add a callback on setAttribute on Prototype ?
For this example, I would like to show an alert("done !") when setAttribute() is finished.
img.setAttribute("src", "http://blabla.com/c.jpg");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could, but I wouldn’t recommend it.
jsFiddle.
This will call
whateverFunctionYouWant()when you do something such asdocument.links[0].setAttribute('href', '/').You seem to want this to call a callback when you change the
srcattribute ofimgelements and the new resource has loaded…jsFiddle.
You could overload
setAttribute()here with a third parameter, which would be the callback.In my opinion and experience, I’d create a different function instead for doing this. Modifying prototypes is one thing, but overloading native DOM methods to do extra things sounds like inviting trouble, especially once a developer unfamiliar with what you’ve done looks at the code.
It goes without saying that if you want the latter example to work < IE9, use the
attachEvent()fallback for adding the event listener.