Using $(this) or this
Using $(this) or this
<script src="
https://code.jquery.com/jquery-1.10.2.js"></script>
<p class='first'>p1</p>
<p class='second'>p2</p>
<p class='third'>p3</p>
<script>
$('p').after(function(i,v) {
return "<div><b>" + $(this).className + "</b></div>";
});
</script>
Output
p1
undefined
p2
undefined
p3
undefined
Why I can't use $(this) here? Why I must use 'this'?
Topic Participants
gunitinug
jakecigar
jtara-jquery
gautamx07