Reputation: 35
$('.someClass').someFunc();
someFunc(){
var thatClass = **???**;
}
I'm wondering how to get the string that I used in the jQuery call into the Function that I chain to it. Is there even a way?
Upvotes: 0
Views: 68
Reputation: 51810
As Anton said : you can look at the selector
property.
However, your jQuery selection may have been built using traversing functions (.parent()
, .eq()
, etc... ), or directly selecting html nodes. In most of those cases, the jQuery object will have an empty selector
string :
var $divs = $('div.mine');
console.log( $divs.selector ); //prints 'div.mine'
var $children = $divs.children();
console.log( $children.selector ); //prints '' (empty string)
var $oneDiv = $( $divs[0] );
console.log( $oneDiv.selector ); //prints '' (empty string)
Upvotes: 0
Reputation: 32581
You can use selector
var thatSelector = $(this).selector; //returns ".someclass"
Upvotes: 3