Karl,
it is not only "href" that has problems, seems all attributes having
an URI string as value have to be read in the way you described.
Some of them are: action, cite, codebase, data, href, longdesc,
lowsrc, src, usemap.
In IE6/7 elements have a predefined number of attributes (minimum 80,
varies depending on the element).
Further complication comes from the fact that IE6/7 getAttribute does
not always return string when a value is present.
document.body.getAttribute("onload"); // function
document.body.getAttribute("style"); // object (not null)
As an example go to "http://www.google.com" with IE6 and other
browsers and type this in the URL:
javascript:alert(document.getElementsByTagName('textarea')
[0].getAttribute('style'));
You will have to add ".cssText" in IE6/7 to read a slightly similar
value:
javascript:alert(document.getElementsByTagName('textarea')
[0].getAttribute('style').cssText);
I don't think all these cases/differences are currently handled and I
don't think they can be handled in a reasonable way.
Diego
On 14 Dic, 16:49, Karl Swedberg <[email protected]> wrote:
> I use .attr() to get the href attribute value, too. If you
> use .getAttribute(), IE6 and IE7 require a second argument to really,
> truly get the attribute: somelink.getAttribute('href', 2)
>
> --Karl
>
> ____________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On Dec 14, 2009, at 10:05 AM, Scott Sauyet wrote:
>
> > On Dec 13, 11:27 pm, Matt <[email protected]> wrote:
>
> > I'm not going to jump into these murky waters, but I want to follow up
> > on this bit:
>
> >> As it is now, I always recommend that attr() be avoided in code, and
> >> if someone uses it in code I am looking at, I tell them to remove it.
> >> It's too fragile and the logic that it is intending to code is not
> >> well documented, so we can't depend on it. Luckily, it's easily coded
> >> around.
>
> > The only place I use attr extensively is when I want the href value of
> > a link for further manipulation to unobtrusively convert non-JS
> > functionality to JS functionality, most commonly when the href is for
> > a document fragment. Do you think it's bad practice to call
>
> > var myDiv=$(item.attr('href'));
>
> > Obviously I could go down to getAttribute, but I've never had a
> > problem using it like this.
>
> > -- Scott
>
> > --
>
> > You received this message because you are subscribed to the Google
> > Groups "jQuery Development" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]
> > .
> > For more options, visit this group
> > athttp://groups.google.com/group/jquery-dev?hl=en
> > .
--
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en.