Side navigation
#229 closed bug (worksforme)
Opened October 03, 2006 09:47PM UTC
Closed October 16, 2006 09:31AM UTC
Last modified June 19, 2007 03:50PM UTC
it is impossible to implicitly abandon search context (without .end())
Reported by: | 3568@emailias.com | 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')
Attachments (0)
Change History (2)
Changed October 03, 2006 10:52PM UTC by comment:1
Changed October 16, 2006 09:31AM UTC by comment:2
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();}