By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,620 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,620 IT Pros & Developers. It's quick & easy.

DOM: removeAttribute() in Internet Explorer

P: n/a

I need to dynamically remove the onmouseout attribute from a link in an
HTML page. I've written code that uses the removeAttribute() method,
believing it's a W3C standard. While it works fine in Mozilla, it doesn't
work as expected in Internet Explorer 6.

If I call the method several times, the first execution returns true and
the rest return false, so it's apparently doing something. However, the
attribute is still there: hovering the mouse triggers the code and
getAttribute() displays the old value.

How should I do it?

Example code:

<p><a id="foo" onmouseout="this.style.color='green'"
href="http://www.google.es">Example link</a></p>

<pre>
<script language="JavaScript" type="text/javascript"><!--
var obj=document.getElementById('foo');
document.writeln(obj.getAttribute('onmouseout'));
obj.removeAttribute('onmouseout');
document.writeln(obj.getAttribute('onmouseout'));
//--></script>
</pre>

Mozilla prints:

this.style.color='green'
null

And link remains unchanged.
Explorer prints:

function anonymous()
{
this.style.color='green'
}
function anonymous()
{
this.style.color='green'
}

And link gets green.

Thank you in advance,
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


Alvaro G Vicario wrote:
I need to dynamically remove the onmouseout attribute from a link in an
HTML page. I've written code that uses the removeAttribute() method,
believing it's a W3C standard. While it works fine in Mozilla, it doesn't
work as expected in Internet Explorer 6.
Unfortunately IE impements some methods with the same name of a method
specified in the W3C DOM but IE's implementation is not what the W3C DOM
specifies. get/setAttribute are in particular broken in IE when it comes
to W3C DOM compliance.
If I call the method several times, the first execution returns true and
the rest return false, so it's apparently doing something. However, the
attribute is still there: hovering the mouse triggers the code and
getAttribute() displays the old value.

How should I do it? <p><a id="foo" onmouseout="this.style.color='green'"
href="http://www.google.es">Example link</a></p> var obj=document.getElementById('foo');


In client-side script in HTML pages if you want to remove an event
handler function assigned as oneventname (in HTML or per script) your
best cross-browser way is
elementObject.oneventname = null;
e.g.
obj.onmouseout = null;

This does not completely remove the attribute but it removes the event
handler.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
*** Martin Honnen wrote/escribió (Mon, 14 Mar 2005 14:17:07 +0100):
In client-side script in HTML pages if you want to remove an event
handler function assigned as oneventname (in HTML or per script) your
best cross-browser way is
elementObject.oneventname = null;
e.g.
obj.onmouseout = null;

This does not completely remove the attribute but it removes the event
handler.


Works like a charm and it looks cross-browser enough. Thanks a lot.
--
-- Álvaro G. Vicario - Burgos, Spain
-- Don't e-mail me your questions, post them to the group
--
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.