Hello i want to replace the text in div when user click on it i have tried this code but there is something wrong with my code
<script>
$(document).ready(function(){
//alert('hi');
$('div').append('hi')
$('div').click(function(){
$('this').append('how r u');
})
})
</script>
please help
Thanks
You are close!
thisis a keyword in JavaScript, but you are using it as a string. Get rid of'aroundthisand you should be fine!Note
If you want to replace the text, you should use
.html()or.text()instead of.append(). Append will leave all text in the div as it is, and add the new text at the end.