Prototype JS and IE 7

So I found a problem with Prototype in IE 7 with he Element.hasAttribute() method. It appears prototype doesn’t add the method very well in IE 7 to the element. Specifically the problem where I was having problems was when I would pass “this” on a anchor tag onClick event.

The solution I found that seems to work well is to take the element that is passed into the function and wrap $() around the element.

Example:

<a onClick=”myFunction(this); return false;”>Link</a>

<script>
function myFunction(element){
   element = $(element);
   if(element.hasAttribute(‘href’))
      //do something
}
</script>

Hope this helps a lot of people out.

This entry was posted in Random. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>