I've been learning more and more about jQuery but here I've become stuck.
I have a code to change the color of a div when a checkbox is cliked, that works fine.
After this I want to be able to change the contents of a textarea on focus, I tried this:
//textarea
$("textarea").focus(function(){
if ($(this).contains('Skriv valg av headset her')){
$(this).replaceWith('');
});
But there is no effect. Do I have some syntax errors or am I taking the wrong approach?
There's the
$.contains
function and the:contains
selector, but nojQuery.fn.contains
. You're looking forval
here I believe:replaceWith
is also wrong here - if that were to work (and it shouldn't I believe because it takes either a DOM element or a HTML text) it would remove thetextarea
element (which is better done withremove
anyway)