Hey! Another small issue (is this not a bug in jQuery?).
I have a text area:
<textarea>Something</textarea>
I want to erase "Something" after clicking, like this:
$("textarea").click(function() { $(this).text(""); });
Good. There are problems when I want to change the text “Something” ONLY when in my text box “Something”:
$("textarea").click( function() { if ($(this).text() === "Something") { $(this).text(""); } });
It works great for all different inputs, but not for textarea. And it works fine without an "if" loop, and what happens here? :)
Thanks a lot!
EDIT
So here is my "real code":
$(".inp").click( function(){ if($(this).val() === "Text" || $(this).val() === "Name" || $(this).val() === "Mail" || $(this).val() === "Site" ) { $(this).val(""); } });
HTML:
<form> <fieldset> <input type="text" name="name" class="inp" value="Name" /> <br /> <input type="text" name="email" class="inp" value="Mail" /> <br /> <input type="text" name="site" class="inp" value="Site" /> <textarea rows="12" name="text" class="inp">Text </textarea> </div>
It works for all inputs except textarea.
source share