Karl Swedberg escribió:
On May 30, 2007, at 10:53 AM, SeViR wrote:
This paragraph from the reference section of the upcoming Learning
jQuery book might help explain why someone would want or need to
preselect a class first. It discusses specifying a tag name rather
than a class, but the same principle applies:
It might not be immediately clear why someone might want to specify
a tag name associated with a particular id, since that id needs to
be unique anyway. However, some situations in which parts of the DOM
are user-generated may require a more specific expression to avoid
false positives. Furthermore, when the same script is run on more
than one page, it might be necessary to identify the id's element,
since the pages could be associating the same id with different
elements. For example, Page A might have <h1 id='title'> while Page
B has <h2 id='title'>.
Ok, I recognize my error :-P, if you want use the same code in
differents pages using the same id's
in different contexts I could want a selector ".class .id" :)
So, tracing this bug. With a simple test in HTML, with jQuery 1.1.1,
1.1.2 and 1.1.3a I have:
versions 1.1.1 and 1.1.2:
One error getting the element by ID, if I don't have one element with
the class ".class"
jQueryCode > // Try to do a global search by ID, where we can
if ( m[1] == "#" && ret[ret.length-1].getElementById
) { <- error ret[ret.length-1] is undefined
In 1.1.3a:
The bug is fixed and works OK :)
jQueryCode > var elem = ret[ret.length-1];
// Try to do a global search by ID, where we can
if ( m[1] == "#" && elem && elem.getElementById ) {
<- checks first if ret[ret.length-1] is defined
Thanks jQuery team ! :-D
As to the bug -- Luc, what version of jQuery are you using? I seem to
recall this bug being fixed at some point, though my memory could be
deceiving me.
If you test it with 1.1.3a and it still produces the error, perhaps
you could log it in the bug tracker?
http://jquery.com/dev/bugs/new/
thanks,
--
Best Regards,
José Francisco Rives Lirola <sevir1ATgmail.com>
SeViR CW · Computer Design
http://www.sevir.org
Murcia - Spain