JQuery object and 'this'

I have the following jQuery function attached to a blur event of n text fields on a web page.

$(document).ready(function() {
        $("input[id$='_txtTuitionAmt']").blur(function() {
            alert(this.value);
        })
    });

It works great. When the user exits from any of the text fields, a pop-up warning appears and displays the value in the text field.

What bothers me is this.value, and whether it is jQuery or JavaScript. Am I using the 'this' object in the right way, or should I do something else to get the value of the element?

Sorry if my question seems a little dark. I'm just trying to deal with the "this" object and how it works. I looked in the jQuery documentation but found nothing on "this".

+3
source share
5

dom ( , document.getElementById("someid") dom). / (.. this.nodeName, this.value,...). , .

$(this) ( $("#someid") $(document.getElementById("someid"))), jquery - , jquery (.. $(this).val(); $(this).find("somenode"),....)

jquery (.. var n = $(this).find("#someid");), jquery, dom, .get(0).

, , . node, onclick (<div id="asdf" onclick="alert(this.id)... - asdf), - - . http://www.quirksmode.org/js/this.html

+12

this = DOM

$(this) = jQuery'ified

JavaScript, . jQuery $(this).val() - .

+7

JQuery doc Core/each:

.

, , ( ), 'this' DOM. , 'this' jQuery.

+3

"this" , jQuery. "this" jQuery, "this" DOM, jQuery. "$ (this)", jQuery, / (). , , jQuery .

: , .

+1

(, ) , :

- Prototype JQuery

The author considers this poor design decision for the jQuery library, but I am not a supporter in any case. I just thought the article was quite interesting.

0
source

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


All Articles