Val
Val

Reputation: 17522

Jquery get selector

I have this jquery script :

$.fn.myFoo = function(){
    alert(this.selector)
    alert($(this).selector);
}

then i call it like so.

$('#myID').myFoo();

I need but it returns empty: i need it to return "myID" i can't seem to find a way to do this can some one help please?

Upvotes: 1

Views: 1256

Answers (1)

rahul
rahul

Reputation: 187020

If you need to get the id then you can use

$(this).attr ( "id" );

inside the function.

See attr

Upvotes: 3

Related Questions