Remove onmouseover event from all <img> tags
asp.net-mvc-3, html, javascript, jquery
Solution
Try like below,
$('img').unbind('mouseover');
No need for looping.. and also it should be `mouseover` not `onmouseover`
Assumptions: You are using `.bind` to bind the `mouseover` handler
I'm not using bind. some images have onmouseover attribute and I want to delete them. I tries $('img').removeAttr('onmouseover') but it still does not work
- Using inline event handler is not a standard.
- Since you are using jQuery, you should bind handler like below.
Code:
$('img').on('mouseover', function () {
//Your code
});
And later can unbind them by using `.off` ->
$('img').off('mouseover');
A work around for what you have (not preferred), (Reference)
$.each($('img'), function () {
$(this).removeAttr('onmouseover');
});
Problem
I doing this way: ``` $.each($('img'), function () { this.unbind('onmouseover'); }); ``` This does not work. Why?