> It's not a bug, it's the documented behavior: > > :first > Matches the first selected element.http://docs.jquery.com/Selectors/first
I cite from the link above: Finds the first table row. $ ("tr:first").css("font-style", "italic"); Seems quite clear > > Let's go through it again. When you call $(this).parents() Sorry but I don't call .parents(), I call .parents('dl:not(:first)') This is not the same When parents is called is called with an expression that filters the result list In the :first page example, for example $("tr:first") is called in the context of document This call filters from all the elements the first tr not the first table If we apply your logic $("tr:first") will return the first table because is the first element in the list of elements in the tree The logic seems to be that parents('dl:not(:first)') first filter the dl elements from the parents list and then filter for :not(:first) If this is not the real behavior (and then there are a bug) jQuery breaks a logic that I think we could ask for with a poll I bet you that your logic don't win > > you get this array of elements: > > [0] <dd> > [1] <dl> > [2] <dd> > [3] <dl> > [4] <dd> > [5] <dl> > > Which are all the element's parents, in order. That's the collection > you're dealing with. > Now, :first refers to the first element ([0]) in that set, and only > that, it has no other meaning. So dl:first will match nothing, as no > dl is the ':first' element. "dd:first" will match the same as dd:eq(0) > or simply :first. > > You have to take in account that the pseudo-selectors are a set of > defined filters, there is no 'semantic' in them. Maybe this could be > improved, but that would be a change in syntax, not a 'bug > correction'. > > Again, that's what slice() is for, slicing the array of elements as > you wish. > > cheers, > - ricardo > > On Feb 3, 12:28 am, Garito <gar...@gmail.com> wrote: > > > Sorry, Ricardo, but this isn't so much logic, isn't it? > > > When I see dl:not(:first) I read give me all dl except the first one > > > Imagine this was a mathematics expression > > > We read from left to right: first filter all dl's with the result > > exclude the first one > > > I can understand a bug but it's dificult to me to understand your > > explanation about this issue even when I test the code with the iPhone > > safari (on Wednesday I could try it with IE to see the dl supposed, on > > FF or Safari don't appears, problem you point) > > > I don't know who decides (at jQuery) what is a bug and what isn't but > > in my opinion this is one of them > > > If jQuery people wants to correct them, ok > > If not ok but jQuery will have it's first point to leave it as soon as > > a better library appears > > > I can do anything more that change my code to solve this jQuery bug > > but this don't change the fact that there is a bug at jQuery > > > Thanks > > > On 3 feb, 02:32, Ricardo Tomasi <ricardob...@gmail.com> wrote: > > > > I haven't seen your page, but I know that styling <dd> and <dt> > > > elements for IE is a pain. And the invalid mark-up might bring you > > > problems with different browsers. The usual behavior for invalid > > > nesting is to close the offended tag to make it valid, so this > > > > <dl> > > > <dt> > > > <div></div> > > > </dt> > > > <dd/> > > > </dl> > > > > would become > > > > <dl> > > > <dt> > > > </dt> > > > </dl> > > > <div></div> > > > <dl> > > > <dd/> > > > </dl> > > > > Firefox is surprisingly tolerant in this case, but I haven't tested > > > elsewhere. Valid mark-up is a safe harbour specially with regards to > > > DOM manipulation. > > > > That aside, I found the issue, it's actually quite simple. > > > > this.parents('dl:not(:first)') > > > > let's see what's happening: > > > - first, this gets you all the parents() for 'root'. Without any > > > filtering, that would be DD, DL, DD, DL etc. > > > - then you ask it to filter the elements which are 'DL's AND are not > > > the first match. Here's the catch: :first refers to the first match in > > > the set, which is a DD element, not a DL one. The DL is never going to > > > be the first match. > > > > :first will always filter according to the current set, before any > > > other expressions in the same call are evaluated. So what you need to > > > do is filter the parents set again: > > > > var slots = $(this).parents('dl').filter(':not(:first)').map(function > > > () { > > > return $(".Texto:first", $(this)).text(); > > > > } > > > > Or use slice() instead as I posted before, that will be much faster as > > > you're just slicing the array without dealing with elements/selectors. > > > > var slots = $(this).parents('dl').slice(1).map(function() { > > > return $(".Texto:first", $(this)).text(); > > > > } > > > > cheers, > > > - ricardo > > > > On Feb 2, 11:35 am, Garito <gar...@gmail.com> wrote: > > > > > Sorry Ricardo but you say the problem is the dt element? > > > > > With this markup I can do what I need in terms of css > > > > > With the css I put the divs inside the dt element to put a label, the > > > > icon and the other div to switch between visible/non visible dd > > > > > How do you think I could put my markup to avoid this problem? > > > > > I don't like your suggest because one of the main reasons to change > > > > from prototype to jquery was the css's selectors and they power > > > > > I thinks this is a jquery's bug, isn't it? > > > > > On 2 feb, 10:02, Ricardo Tomasi <ricardob...@gmail.com> wrote: > > > > > > Ah that's quite confusing mark-up. A <dt> element can only contain > > > > > inline elements, certainly not divs and other definition lists. Nested > > > > > definition lists make no sense! I couldn't find the problem. > > > > > > Try $(this).parents('dl').slice(1) or $(this).parents('dl').slice > > > > > (0,-1), that will probably work. > > > > > > cheers, > > > > > - ricardo > > > > > > On Feb 1, 10:57 pm,Garito<gar...@gmail.com> wrote: > > > > > > > Gracias, Ricardo! > > > > > > I change the code with the complete test case for my issue > > > > > > > Sorry for the identation but the original code is generated and I > > > > > > copy/ > > > > > > paste with firebug > > > > > > > If I'm not wrong, with the selector 'dl:not(:last)' SITE dl is > > > > > > incorrect in the returned list because is the last dl (if not 'dl' > > > > > > will be equal to 'dl:not(:last)') > > > > > > > am I confused or there is a bug? > > > > > > > Thanks! > > > > > > > On 1 feb, 21:07, Ricardo Tomasi <ricardob...@gmail.com> wrote: > > > > > > > >http://jquery.nodnod.net/cases/85 > > > > > > > > Parece ok aqui. Pode ser alguma outra coisa na tua página, não dá > > > > > > > pra > > > > > > > saber sem ver o html. > > > > > > > -------- > > > > > > > Seems to work fine here. Could you post a complete test page > > > > > > > showing > > > > > > > this issue? > > > > > > > > - ricardo > > > > > > > > On Feb 1, 1:25 pm,Garito<gar...@gmail.com> wrote: > > > > > > > > > Hi! > > > > > > > > Please, consider this code: > > > > > > > > > $.fn.url2 = function(absoluta) { > > > > > > > > var slots = > > > > > > > > $(this).parents('dl:not(:last)').map(function() { > > > > > > > > return $(".Texto:first", > > > > > > > > $(this)).text(); > > > > > > > > }); > > > > > > > > var slots2 = > > > > > > > > $(this).parents('dl').map(function() { > > > > > > > > return $(".Texto:first", > > > > > > > > $(this)).text(); > > > > > > > > }); > > > > > > > > return slots.get().join("/") + ' -- ' + > > > > > > > > slots2.get().join("/"); > > > > > > > > }; > > > > > > > > > The funny thing of this code is that slots and slots2 have the > > > > > > > > same > > > > > > > > items > > > > > > > > Could you point me why slots put the last dl? > > > > > > > > > I suppose that dl:not(:last) retrieves all the parents except > > > > > > > > the last > > > > > > > > one but this don't work > > > > > > > > > Thanks!