javascript - jQuery this inside event -



javascript - jQuery this inside event -

i tought understand utilize of this in jquery/js, showes me i'm wrong. wanted add together class on dom element , used this:

$("#content").on("click",function(){ this.addclass("bonus"); });

but nil happened, changed sec line of code , worked:

$("#content").addclass("bonus");

shouldn't this in first illustration refer $("#content") already?

this refers dom element triggered. it's not jquery object, native dom object.

you need do:

$(this).addclass("bonus");

javascript jquery dom

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -