Alternative to .selector property now that it is removed in jQuery 1.9

As in jQuery 1.9, the .selector property of jQuery objects has been removed. (I'm a little confused why exactly). I really use it in several unique scenarios, and I know that I could do other things to prevent this. Just wondering if anyone knows any other way to capture the selector with 1.9?

 $('#whatever').selector // (would of returned '#whatever') 

One example of where I need .selector is that I already have a group of checkboxes with the name name , and I want to see, inside this group, which one is checked:

jsFiddle DEMO

 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 for jQuery objects

The remaining target of the deprecated .selector property in the jQuery object must support the deprecated .live () event. In 1.9, jQuery no longer attempts to save this property in chain methods, since the use of chain methods was never supported with .live (). Do not use the .selector property for a jQuery object. The jQuery migration plugin is not trying to save this property.

+4
source share
1 answer

Actually there should not be many reasons necessary for the initial selector. In your specific use case, if you want to narrow your selection of items, you can use .filter [docs] :

 $test.filter(':checked').attr('id') 

$('#whatever').selector still seems to work. The documentation says: "In version 1.9, jQuery no longer tries to support this property in chain methods [...]." Although http://api.jquery.com/selector claims it was removed in 1.9. I don’t know, this is a bit confusing.

+3
source

All Articles