Ticket #7348 (closed enhancement: wontfix)
Current "set" of Matched Elements: jQuery.self or jQuery.last
|Reported by:||anonymous||Owned by:|
I am constantly finding myself wanting to reference the current set of elements inside a chain of commands. Let me explain with a couple of examples:
var r = $('#test'); var g = r.find('span[data-Name=Name]'); g.css('width', g.width() + 10); var i = r.find('input[name=Date]'); i.attr('data-OldValue', i.val()).val('now');
As you can see, both g and i needed to reference themselves within the methods executed against them. There's no way for me to turn this into a chain of commands using the end() method because of this. I think jQuery needs a variable that holds the current set of elements (e.g. $.$, $._, $.self, $.last, ...); the above code then could be written like so:
$('#test').find('span[data-Name=Name]') .css('width', $.$.width() + 10) .end().find('input[name=Date]') .attr('data-OldValue', $.$.val()).val('now') .end();
It's more for convenience than reducing code length, however, if you keep this reference name small (such as $.$ or $._), it would be both a convenience and reduce the overall code length slightly. It just seems like this would be a great compliment to the end() method.
I apologize ahead of time if there's already a feature for this or someone knows of a way to do it without breaking a chain.
- Priority changed from undecided to low
- Component changed from unfiled to core
- Milestone 1.5 deleted