JQuery attr () not returning in IE7

I have me at a standstill. I use the β€œfor” attribute on some links to identify the element on which they should act. Everything seems to work fine in Firefox, IE9 and IE8 ... but IE7 breaks and returns "undefined."

Here is the gist of the jQuery code I'm using:

$(document.ready(function() { var editor_icons = $('.edit-button'); editor_icons.each(function() { var $this = $(this), parent = $('#' + $this.attr('for')); var left = parent.position().left + parent.innerWidth() - 58 - 3, top = parent.position().top + 3; // ... you get the point ... }); }); 

An example of an HTML element that it should act on:

 <div id="content_wrapper"> <a class="edit-button" href="javascript:void(0);" for="index_primary_content" /> <div id="index_primary_content"> .... </div> </div> 

Before pointing this out, I understand that anchors should not be automatically closing elements. The HTML I am sending from my application is <a></a> , and IE interprets it as <a /> . I added &nbsp; between the elements to make sure that this is not a problem of interpretation, and I get the same error.

The problem is that $this.attr('for') returns "undefined", so parent.position().left throws the error "object is null or undefined".

I dug up the clock variables a bit, and I see that the selectors work, and $this in this context selects the right elements and has a set of attributes for "... but jQuery isn 'I think I think.

As I said, it works fine in Firefox, IE9 and IE8 ... just not IE7. Ideas?

For reference, I am using jQuery 1.6.2 ...

+4
source share
2 answers

Instead of for , use your own attribute instead; target_ele e.g.

Your editor will yell at you, but it will work.

+1
source

I believe this is your jQuery Bug Ticket problem

This is because the "for" property when used in HTML is actually "htmlFor", for example, in the label element. This will be true of any of the special cases in jQuery.props that I suspect. XML documents do not receive this special treatment, so the "for" will be "for" there. I'm not sure if this is worth fixing or just documenting.

+2
source

All Articles