JavaScript is from jQuery this

Is there a way to get javascript from jQuery?

+3
source share
4 answers

this== this, regardless of this.

this - this is not jquery, it is a special, somewhat confusing javascript keyword that describes the current execution area.

Your task can determine or control what it is this.

+12
source

Exist:

$('a').click(function(){
   var jqueryobject = $(this);
   var domelement   = this;
}); 

Inside such a closure, it thisalways represents a native DOM elementthat should / may be wrappedin a jQuery object.

If you already have a jQuery object and need to DOM elementuse

var DOMelement = $(this)[0];

or

var DOMelement = $(this).get(0);

jQuery array like objects, []. jQuery . Get() . DOM element .

- this?

  • this
  • this ,
  • this
  • this - protoypal.
+8

, , . -, , jQuery - , Javascript. this "" .

Perhaps you want to get the actual DOM element instead of a jQuery object? You can use .get():

// let say there a single paragraph element
var obj = $('p');   // obj is a jQuery object 
var dom = obj.get(0);  // dom is a DOM element
+1
source

Try to access this(DOM element) instead of $(this)(jquery object).

0
source

Source: https://habr.com/ru/post/1752396/


All Articles