html - jQuery noob: (this).replacewith am I doing it wrong? -


i've been learning more , more jquery here i've become stuck.

i have code change color of div when checkbox cliked, works fine.

after want able change contents of textarea on focus, tried this:

    //textarea     $("textarea").focus(function(){         if ($(this).contains('skriv valg av headset her')){          $(this).replacewith('');     });   

but there no effect. have syntax errors or taking wrong approach?

jsfiddle example here.

there's $.contains function , :contains selector, no jquery.fn.contains. you're looking val here believe:

$('textarea').focus(function(){     var t = $(this);      if(t.val().indexof('skriv valg av headset her') !== -1) {         t.val('');     } }); 

replacewith wrong here - if work (and shouldn't believe because takes either dom element or html text) remove textarea element (which better done remove anyway)


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -