I'm trying to add an on click function to a div using these lines of code but the click event doesnt trigger the alert.
var str="<script>$(this).on(\"click\",function(){alert('hello');})";
str+="<";
str+="/script>";
$("div:contains('Send')").last().append(str);
I've also tried this and $(this)[0] but these give me the error this.on/ $(this)[0].on is not a function
I don't know what Im doing wrong and would appreciate any and all help on the matter.
"<script>$(this).on(\"click\",function(){alert('hello');})";what will this represent here?this, it represents current object. So when you do obj.alert(), in alert, this will represent obj. Also for your case refer to this JSFiddle for reference. Hope it helps.$("div:contains('Send')").last().on("click",function(){alert('hello');})?