jquery - this reference in JavaScript -
Today I was writing some basic stuff of Java script, while I had to face the problem. Although I was able to solve this problem, but the reason was not known why this was not working. Here is my code
$ ('document'). Ready (function () {$ (this) .click (function () {var node1 = $ (this); a = node1 text (); console.log (a);});});
In this console I see the empty string. But if I change $ (this) .click (function {...}) from
$ ('. Some_class_name'). Click (function {.....});
works fine in comparison to my code and I display the text value of the button that was clicked. I want to know what is wrong with the above code.
You should find it, use to get the text inside the clicked element E.target
which exists inside the document.
$ ('document'). Ready (function () {$ (this). Click (function (e) {var node 1 = $ (e.target); var a = node1.text (); console.log (a);});} );
Comments
Post a Comment