Examples of this keyword usage in javascript and jquery,
This article analyzes the usage of the this keyword in javascript and jquery. We will share this with you for your reference. The details are as follows:
This indicates the current object. The current object can be a form, <p>, or any other element.
1. usage of this in javascript:
JS section:
<script type="text/javascript"> function chimg(obj){ obj.src="./images/2.jpg"; }</script>
HTML section:
Copy codeThe Code is as follows:
2. usage of this in jquery:
JS section:
<script type="text/javascript"> $(document).ready(function(){ alert(this.src); })</script>
HTML section:
Copy codeThe Code is as follows:
I hope this article will help you design JavaScript programs.
Articles you may be interested in:
- Learn the this keyword of javascript
- This keyword in JavaScript is illustrated.
- This in JavaScript
- Examples of this usage in js
- Differences between $ this and $ (this) in jQuery)
- This and $ (this) in jQuery)
- Usage of this in jquery