Speed has absolutely nothing to do with this. You are trying to speed compare methods that do completely different things:
$('#foo'); // select the element with the id #foo $('#foo > .bar'); // select the elements with the class bar that are direct children of the element with the id #foo $('#foo').find('.bar'); // select the elements with the class bar that are direct children of the element with the id #foo $('.foo').filter('.bar'); // select all elements with the class foo then filter that list to only include the ones that also have the class bar $(e.target).closest('li'); // given a node for an event, backtrack through the document to find the closest li node (this is meant for event delegation type tasks) Using $(this+' > .quantite') WILL NOT WORK when /this/ is a document node. You have to use $(this).find('> .quantite'); or $(this).children('.quantite'); should work to. ~Daniel Friesen (Dantman, Nadir-Seen-Fire) Gilles wrote: > Ah zut, I forgot the >, and I was hoping i could actually help on that > one lol, but otherwise this would work normaly no? > (sorry to ask but newbie so I check to make sure) > > $(this+' > .quantite') (also I think it's mention somewhere in this > group that find is faster (for the moment only)) > > Also would the new closest() method work? > > $(this).closest('.quantite'); (is that faster or slower than the above > or / and find) > > On Mar 31, 5:27 pm, Daniel Friesen <nadir.seen.f...@gmail.com> wrote: > >> If /this/ is a node as I expect it is in that context, it should >> actually be $(this).find('.quantite'); >> >> ~Daniel Friesen (Dantman, Nadir-Seen-Fire) >> >> Gilles wrote: >> >>> Bonjour! >>> >>> Stupid question, but you have made sure to wrap your code inside $ >>> (function(){ /* your code */ }); yes? >>> As otherwise JQuery might have trouble locating what you need if it >>> isn't. >>> >>> Also could you provide the HTML source as rendered by the browser, it >>> makes copy/pasting/testing easier :) >>> >>> $("this ~ .quantite") is wrong tho i believe it should be $(this >>> +'.quantite') as this is a variable >>> >>> (unless it is interpreated as variable between double quote like in >>> PHP, but I am pretty sure it doesn't) >>> >>> On Mar 31, 3:14 pm, elpatator <romain.simi...@gmail.com> wrote: >>> >>>> Although Jquery offers multiple ways in selecting DOM elements, I >>>> can't figure out how to do this, as i'm not that good at it. >>>> Here's the deal : >>>> my html goes like this >>>> <logic:iterate id="ligneCommande" name="commande" >>>> property="lignesCommande" indexId="index"> >>>> <div class="ligneArticle"><c:set >>>> var="nbLigneCommandes" >>>> value="${nbLigneCommandes+1}" /> >>>> <bean:define id="articleId" >>>> name="ligneCommande" >>>> property="article.id" /> >>>> >>>> <div >>>> class="blocGauche"><bean:define id="articleId" >>>> name="ligneCommande" >>>> property="article.id" /> >>>> <img class="visuelArticle" >>>> src="/images/visuelsArticles/dim1/$ >>>> {ligneCommande.article.articleReference.reference}_dim1.jpg" >>>> height="60" width="60" /> >>>> >>>> <span class="libelleArticle"> >>>> <bean:write >>>> name="ligneCommande" >>>> property="article.articleReference.libelle" /> >>>> </span> >>>> </div> >>>> <div class="blocDroit"> >>>> <span class="prixUnitaire"> >>>> <bean:write >>>> >>>> name="ligneCommande" property="prixUnitaire" format="" >>>> formatKey="main.format.prix"/> >>>> <input >>>> type="hidden" class="prixProduit" name="prix${index}" >>>> value="${ligneCommande.prixUnitaire}"></input> >>>> <input >>>> type="hidden" >>>> >>>> name="montantDeLigne${index}" value="$ >>>> {ligneCommande.prixTotal}"></input> >>>> </span> >>>> >>>> <table class="calculette"> >>>> <tr> >>>> <td> >>>> <html:text >>>> styleClass="quantite" >>>> property="quantiteLigneCommande(${ligneCommande.id})" styleId="$ >>>> {ligneCommande.id}"/> >>>> </td> >>>> <td> >>>> >>>> <img class="plus" src="/images/quantiteIncrement.gif" >>>> alt="Plus" /> >>>> </td> >>>> <td> >>>> >>>> <img class="moins" src="/images/quantiteDecrement.gif" >>>> alt="Moins" /> >>>> </td> >>>> </tr> >>>> </table> >>>> >>>> <div >>>> id="montantDeLigneAfficher${index}" class="prixTotal"> >>>> <bean:write >>>> name="ligneCommande" property="prixTotal" format="" >>>> formatKey="main.format.prix" /> >>>> </div> >>>> </div> >>>> <div class="clear"></div> >>>> </div> >>>> <div class="clear"></div> >>>> </logic:iterate> >>>> >>>> As you can see, I iterate on each line, that's named .ligneArticle ; >>>> What I wish to do is, on click on >>>> <img class="plus" src="/images/quantiteIncrement.gif" alt="Plus" /> or >>>> <img class="moins" src="/images/quantiteDecrement.gif" alt="Moins" />, >>>> traverse back up from my button, in order to get it's current (and >>>> unique) lingneArticle, to get back down and work on quantity input. >>>> Right now, my js looks likes this : >>>> $(".plus").click(function (){ >>>> var quantite = $("this ~ .quantite").val(); >>>> quantite++; >>>> if (quantite<=0){ >>>> quantite=0; >>>> } >>>> $("this ~ .quantite") >>>> .text(quantite) >>>> .val(quantite); >>>> calculMontantPanier(); >>>> }); >>>> >>>> $(".moins").click(function (){ >>>> var quantite = >>>> $(this).find(".quantite:input").val(); >>>> quantite--; >>>> if (quantite<=0){ >>>> quantite=0; >>>> } >>>> $(this).find(".quantite:input") >>>> .text(quantite) >>>> .val(quantite); >>>> calculMontantPanier(); >>>> }); >>>> >>>> As you can see, my probleme is related to DOM crawling back up from $ >>>> (this) (my button), and then down to it's direct >>>> neigbour .quantite:input . >>>> >>>> Thanks for your help. >>>> > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---