943,177 Members | Top Members by Rank

Ad:
Sep 2nd, 2010
0

Empty jQuery selector

Expand Post »
If I would have a simple function like this:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. jQuery.fn.example = function(){
  2. this.remove();
  3. }

and call it with an empty selector:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $().example();

What element would then this be pointing to? Or is there a way to make a function able to be executed through both $.example(), without a selector, and with $(something).example()? If so, how can I find out which way the function has been executed so I can have different actions depending way of execution?
Similar Threads
Reputation Points: 10
Solved Threads: 10
Junior Poster
gunnarflax is offline Offline
164 posts
since Jan 2010
Sep 5th, 2010
0
Re: Empty jQuery selector
Basically, "this" refers to the selected element you have chosen to remove. Let's say, if you have called the .example() function like ( $("a").example(); ), "this" will refer to all link elements in your page. So basically, I think you don't have to call the $.example() function if you are not pertaining to any particular element.
Reputation Points: 10
Solved Threads: 5
Light Poster
lambing is offline Offline
30 posts
since Feb 2010
Sep 6th, 2010
0
Re: Empty jQuery selector
What I meant was what would happen if a script dependent of a selector would be called without a selector used, what would then be automatically selected? The jQuery object or the document object perhaps? Do you understand my question?
Reputation Points: 10
Solved Threads: 10
Junior Poster
gunnarflax is offline Offline
164 posts
since Jan 2010
Sep 6th, 2010
0
Re: Empty jQuery selector
Yeah, I do understand your question. That's a good question, but I never encountered that kind of situation yet so basically, I don't have any idea about it.
Reputation Points: 10
Solved Threads: 5
Light Poster
lambing is offline Offline
30 posts
since Feb 2010
Sep 6th, 2010
0
Re: Empty jQuery selector
Ok thanks anyway, if you ever find out, let me know will you?
Reputation Points: 10
Solved Threads: 10
Junior Poster
gunnarflax is offline Offline
164 posts
since Jan 2010
Sep 6th, 2010
0
Re: Empty jQuery selector
OK, I will.
Reputation Points: 10
Solved Threads: 5
Light Poster
lambing is offline Offline
30 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Ajax Date picker
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: changing an AJAX $_GET to $_POST





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC