Jquery re-declare $ (this)

Unable to redeclare $.(this)after function $.click()? because none of them work:

$(this) = $(this).find('span');
var $(this) = $(this).find('span');
+3
source share
3 answers

You can var fooonly declare if it foois a legal identifier.

$(this)is the result of calling a function with a name $with an argument this, so it is not legal in a declaration.

Also, you should not overwrite this- it will cause big head scratches in the future!

If you need a local variable to hold the jQuery version this, then the general convention is:

var $this = $(this);
var $span = $this.find('span');

( , ) $ , jQuery, DOM.

( ) :

var jqobj = $(myobj)

myobj jQuery.

+4

$(this) , . -,

var saved = $(this);
saved = $(this).find('span');

, , , .

+3
$('some').on('click', function() {
  var refrence = $(this);
  var span = refrence.find('span')
  // to override the $this you can use
  refrence = refrence.find('span');
});
+2
source

All Articles