#229 closed bug (worksforme)
it is impossible to implicitly abandon search context (without .end())
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | major | Milestone: | 1.0 |
Component: | core | Version: | |
Keywords: | search context find abandon | Cc: | |
Blocked by: | Blocking: |
Description
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 16 years ago by
comment:2 Changed 16 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
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.
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();}