[jQuery] Re: Find reverse? Parent?
maybe $(this).prev(.picture).append( On Aug 31, 2:36 pm, Jottae smallj...@gmail.com wrote: Hi guys. I am wanting to click the link with the class test the function append href taking the (already up and running) appears in the picture div, but only in the same div lol where there is also a class test. suggestions? --- This is html code: div id=lol div class=picture lorem ipson /div a class= test href=http://www.google.com/myckey.gif;Google/a /div div id=lol div class=picture lorem ipson /div a class= test href=http://www.google.com/donald.gif;Google/a /div --- This is code jQuery. $(.test).click(function() { var url = this.href; $(.picture).append(img src='+url+'/); --- This is wrong --- find reverse?parent? }); Thanks. =D
[jQuery] Re: Find reverse? Parent?
In this case the DIV is a sibling, not a parent, of the A. So you want to select on that. If the HTML is complete as you show it, the selector needed is simply the .prev() of your A On Aug 31, 2:36 pm, Jottae smallj...@gmail.com wrote: Hi guys. I am wanting to click the link with the class test the function append href taking the (already up and running) appears in the picture div, but only in the same div lol where there is also a class test. suggestions? --- This is html code: div id=lol div class=picture lorem ipson /div a class= test href=http://www.google.com/myckey.gif;Google/a /div div id=lol div class=picture lorem ipson /div a class= test href=http://www.google.com/donald.gif;Google/a /div --- This is code jQuery. $(.test).click(function() { var url = this.href; $(.picture).append(img src='+url+'/); --- This is wrong --- find reverse?parent? }); Thanks. =D
[jQuery] Re: find reverse
Do you want to use parent? $(#findme).parent() http://docs.jquery.com/Traversing/parent#expr On Wed, May 27, 2009 at 9:19 AM, Peter Marino marino.pe...@gmail.comwrote: Hi jQuery Group, is it possible find a node backwards instead of forwards. i.e. div id=test0 div id=findme / div now I would like to do (remember find_reverse does not exist) $(#findme).find_reverse(#test0); is there any method to do a find_reverse??? regards, Peter Wraae Marino -- Power Tumbling - http://www.powertumbling.dk OSG-Help - http://osghelp.com
[jQuery] Re: find reverse
Hi Caires, something like that but it should continue up the parent until it finds it or return null peter On Wed, May 27, 2009 at 2:21 PM, Caires Vinicius caire...@gmail.com wrote: Do you want to use parent? $(#findme).parent() http://docs.jquery.com/Traversing/parent#expr On Wed, May 27, 2009 at 9:19 AM, Peter Marino marino.pe...@gmail.comwrote: Hi jQuery Group, is it possible find a node backwards instead of forwards. i.e. div id=test0 div id=findme / div now I would like to do (remember find_reverse does not exist) $(#findme).find_reverse(#test0); is there any method to do a find_reverse??? regards, Peter Wraae Marino -- Power Tumbling - http://www.powertumbling.dk OSG-Help - http://osghelp.com -- Power Tumbling - http://www.powertumbling.dk OSG-Help - http://osghelp.com
[jQuery] Re: find reverse
One thing to remember Peter is that jQuery returns an array. You could do a more comprehensive search, then reverse the returned value. Something like this might work: var $myDivs = $('div').reverse; then search through $myDivs for your preferred value. andy _ From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Peter Marino Sent: Wednesday, May 27, 2009 7:20 AM To: jquery-en@googlegroups.com Subject: [jQuery] find reverse Hi jQuery Group, is it possible find a node backwards instead of forwards. i.e. div id=test0 div id=findme / div now I would like to do (remember find_reverse does not exist) $(#findme).find_reverse(#test0); is there any method to do a find_reverse??? regards, Peter Wraae Marino -- Power Tumbling - http://www.powertumbling.dk OSG-Help - http://osghelp.com
[jQuery] Re: find reverse
On May 27, 2:19 pm, Peter Marino marino.pe...@gmail.com wrote: Hi jQuery Group, is it possible find a node backwards instead of forwards. isn't that parents()? (not parent, parents :) http://docs.jquery.com/Traversing/parents
[jQuery] Re: find reverse
hi, did not see the parents() method before now.. it does look this is what I need.. will check when I get home from work... thanks peter On Wed, May 27, 2009 at 4:49 PM, M.M. mario.maru...@gmail.com wrote: On May 27, 2:19 pm, Peter Marino marino.pe...@gmail.com wrote: Hi jQuery Group, is it possible find a node backwards instead of forwards. isn't that parents()? (not parent, parents :) http://docs.jquery.com/Traversing/parents -- Power Tumbling - http://www.powertumbling.dk OSG-Help - http://osghelp.com
[jQuery] Re: find reverse
The closest()-method (available since jquery 1.3) would be ideal here, as it stops searching when an element matching the expression is found. See also: http://docs.jquery.com/Traversing/closest Please also note that ids are unique within a document, so just $ (#test0) should be fast enough. On May 27, 4:58 pm, Peter Marino marino.pe...@gmail.com wrote: hi, did not see the parents() method before now.. it does look this is what I need.. will check when I get home from work... thanks peter On Wed, May 27, 2009 at 4:49 PM, M.M. mario.maru...@gmail.com wrote: On May 27, 2:19 pm, Peter Marino marino.pe...@gmail.com wrote: Hi jQuery Group, is it possible find a node backwards instead of forwards. isn't that parents()? (not parent, parents :) http://docs.jquery.com/Traversing/parents -- Power Tumbling -http://www.powertumbling.dk OSG-Help -http://osghelp.com
[jQuery] Re: find reverse
Be aware that closest() returns the element itself if no match is found. I prefer to use $(el).parents('xx:first') to avoid that. Peter, no jQuery method will return null. If nothing is found it will return an empty collection (length == 0). On May 27, 2:03 pm, dabear bjorni...@gmail.com wrote: The closest()-method (available since jquery 1.3) would be ideal here, as it stops searching when an element matching the expression is found. See also:http://docs.jquery.com/Traversing/closest Please also note that ids are unique within a document, so just $ (#test0) should be fast enough. On May 27, 4:58 pm, Peter Marino marino.pe...@gmail.com wrote: hi, did not see the parents() method before now.. it does look this is what I need.. will check when I get home from work... thanks peter On Wed, May 27, 2009 at 4:49 PM, M.M. mario.maru...@gmail.com wrote: On May 27, 2:19 pm, Peter Marino marino.pe...@gmail.com wrote: Hi jQuery Group, is it possible find a node backwards instead of forwards. isn't that parents()? (not parent, parents :) http://docs.jquery.com/Traversing/parents -- Power Tumbling -http://www.powertumbling.dk OSG-Help -http://osghelp.com