jQuery
New Wave Javascript
discuss » cross-browser compatibility with for attribute
Posted: Wed Feb 8 12:48:10 EST 2006
From: John Resig <
jeresig at gmail.com
>
On 2/8/06, Andrea Ca'Zorzi <
andrea.cazorzi at gmail.com> wrote:
>
I was indeed half-suspecting that something similar might be the case
>
with css properties but hadn't used them yet.
>
>
For the time being, for my original problem, I just use
>
>
$("label[@htmlFor]").add("label[@for]")
>
>
and everything works like a charm... (if performance is not an issue,
>
but that's rarely the case in a form, where the user's reaction time
>
is anyway so much slower than that of the browser).
>
>
For the css rules, the same trick should apply, I believe:
>
>
$("p").css("float","right").css("cssFloat","right")
>
>
Admittedly, none of the two solutions qualify as 'smart', but they're
>
still pretty compact.
Agreed, the problem still needs some serious tackling - developers
shouldn't have to know about the weird cssFloat, htmlFor issues that
exist - they should just be allowed to code. To tighten up your above
code, a little bit:
$("label[@htmlFor],label[@for]")
and
$("p").css({float:"right",cssFloat:"right"})
I currently have the comma operator for dealing with multiple
expression (like the above label...,label... business) but I don't
have a way for deal with multiple 'filters' (e.g. doing
label[@htmlFor|@for]) that might make for a nice addition - and a
faster one, at that.
Thanks for the help.
--John
>
>
Andrea
>
>
>
On 2/6/06, John Resig <jeresig at gmail.com> wrote:
>
> Good catch Andrea!
>
>
>
> Currently, jQuery doesn't interpret things like that, making them
>
> sane. You'll also see this when working with the CSS attributes:
>
> $("p").css("float","right");
>
> vs
>
> $("p").css("cssFloat","left");
>
>
>
> and even the use of:
>
> $("p").css("fontWeight","bold");
>
> instead of:
>
> $("p").css("font-weight","bold");
>
>
>
> I'll see if I can't figure out a smart way to work around these issues.
>
>
>
> --John
>
>
>
> On 2/6/06, Andrea Ca'Zorzi <andrea.cazorzi at gmail.com> wrote:
>
> > Hi,
>
> >
>
> > I love to work with this library because of the beatifully compact
>
> > code it allows me to write.
>
> >
>
> > I think there is a browser compatibility problem with xpath searches
>
> > using attributes like 'for' and 'class'. These work fine on
>
> > gecko-based browsers, while you need to use 'htmlFor' and 'className'
>
> > on IE6/Win.
>
> >
>
> > Try this:
>
> >
>
> > alert($("//div[@className]").size());
>
> > alert($("//div[@class]").size());
>
> >
>
> > and this:
>
> >
>
> > alert($("//label[@htmlFor]").size());
>
> > alert($("//label[@for]").size());
>
> >
>
> > on Firefox or IE6/Win and you'll see where the problem is.
>
> >
>
> > Otherwise, great work.
>
> >
>
> > Andrea Ca'Zorzi
>
> >
>
> > _______________________________________________
>
> > jQuery mailing list
>
> > discuss at jquery.com
>
> > http://jquery.com/discuss/
>
> >
>
>
>
>
>
> --
>
> John Resig
>
> http://ejohn.org/
>
> jeresig at gmail.com
>
>
>
> _______________________________________________
>
> jQuery mailing list
>
> discuss at jquery.com
>
> http://jquery.com/discuss/
>
>
>
>
_______________________________________________
>
jQuery mailing list
>
discuss at jquery.com
>
http://jquery.com/discuss/
>
--
John Resig
http://ejohn.org/jeresig at gmail.com