Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#229 closed bug (worksforme)

it is impossible to implicitly abandon search context (without .end())

Reported by: 3568@… Owned by:
Priority: major Milestone: 1.0
Component: core Version:
Keywords: search context find abandon Cc:
Blocked by: Blocking:


This issue is similar to #48 I want to be able to abandon search context by making separate js statement without using .end() I can not do that because jquery preserves context across js statements If I have jquery object node then the following 2 blocks are equivalent, but they shoutl not be: 1) node.find('td.id').html('123') node.find('td.name').html('Aleksey P') 2) node.find('td.id').html('123').find('td.name').html('Aleksey P')

In order to achieve proper results block 1 must look like: node.find('td.id').html('123').end() node.find('td.name').html('Aleksey P').end() ,which is ugly

Easy way to overcome that problem extending jquery is this: jQuery.prototype.$=function(path){return $(this).find(path)} Then my block#1 will look like: node.$('td.id').html('123') node.$('td.name').html('Aleksey')

Change History (2)

comment:1 Changed 11 years ago by 3568@…

Another good reason of why it needs to be done my way is that current jquery.find implementation makes JavaScript "with" keyword useless. I want to be able to do this: with($(table tr)){find('td.id').html('123');find('td.name').html('Aleksey P');} and currently I have to do that:with($(table tr)){find('td.id').html('123').end();find('td.name').html('Aleksey P').end();}

comment:2 Changed 11 years ago by joern

Resolution: worksforme
Status: newclosed

This isn't a bug, it is by design. There have been discussion to extend all destructive methods like find(), allowing you to pass a function that works on the jQuery filtered object without modifying the original one.

According to several resources, using "with" is error-prone and should be avoided.

Note: See TracTickets for help on using tickets.