Please consider the following sample code:
Please, kindly do not follow the low quality articles from W3Schools. For your solution:
btn
is not a jQuery object. It is a JavaScript HTMLElement
..prepend()
function is a jQuery function.Your code now should be:
$(document).ready(function(){
$("#btn1").click(function(){
var btn = $(this);
btn.prepend("Prepended text. ");
});
});
Working Snippet
$(document).ready(function(){
$("#btn1").click(function(){
var btn = $(this);
btn.prepend("Prepended text. ");
});
});
This is a paragraph.
See the working snippet above. Click on the Run Code Snippet and click the button inside.