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?
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
Post a Comment