What is the difference between this and $(this) in jQuery?
<button id="b" data-name="Save">Click</button>
$('#b').on('click', function () {
console.log(this.id); // DOM property
console.log($(this).data('name')); // jQuery method
console.log(this === $(this)[0]);
});
$('#b').click();
Console output
b
Save
true
Learn more about the similar topics:
| Tutorials |
|---|
| jQuery Selectors |
| jQuery Traversing: Ancestors |
| jQuery Traversing: Descendants |
| jQuery Traversing: Siblings |
| jQuery Traversing: Filtering |
| Exercises & Assignments |
|---|
| Write jQuery code to count the items of a list |
| Write jQuery code to find the total of a table column |
| Write jQuery code to add alternate row colors to a table |