As of jQuery 1.9 the .selector
property of jQuery objects has been removed. (I'm a little confused as to why, exactly). I actually use it in a few unique scenarios, and I know that I could do other things to prevent this. Just wondering if anyone knows another way of grabbing the selector as of 1.9?
$('#whatever').selector // (would of returned '#whatever')
One example of where I need .selector is when I already have a group of checkboxes by name, and I want to see, within that group, which one is checked:
var $test = $('input[name="test"]');
console.log( $test );
console.log( $(':checked', $test).attr('id') ); // returns --undefined--
console.log( 'now with .selector: ');
console.log( $($test.selector + ':checked').attr('id') ); // returns correct
From the docs: .selector property on jQuery objects
The remaining purpose of the deprecated .selector property on a jQuery object is to support the deprecated .live() event. In 1.9, jQuery no longer attempts to maintain this property in chained methods, since the use of chained methods was never supported with .live(). Do not use the .selector property on a jQuery object. The jQuery Migrate plugin does not attempt to maintain this property.
$('#whatever').selector
still seems to work. The documentation says "In 1.9, jQuery no longer attempts to maintain this property in chained methods [...]". Though api.jquery.com/selector claims it was removed. I don't know, it's a bit confusing. I guess an official statement might clarify this, maybe you can post in their mailing list/forum/group/whatever. – Zug.filter
is for: api.jquery.com/filter.$test.filter(':checked').attr('id')
.$(':checked', $test)
cannot work, becauseinput
elements don't have any descendants. – Zug.filter()
thing as an example for an answer. @FelixKling – Scevor.selector
property on a jQuery object. – Thilda