jquery $(this) returns [object object] instead of DOM reference
12,959
Solution 1
To get the DOM element use $.get():
$(this).get(0);
Solution 2
$(this) returns [object object] because it's a jquery object.Try console.log(this), you will get the
dom element you need.
Author by
Dušan
Updated on June 14, 2022Comments
-
Dušan almost 2 years
In this situation
$(document).on('click', '.photo-actions .photo-link', function () { console.log($(this)); });
$(this)
retrurns[object object]
instead of DOM refference for an element which is clicked. Why is this the case and how to get the DOM reference? and if i write$(this).attr('id');
it returns the id of element which it should.