I want to set the placeholder using the data- * attribute. I tried with jQuery. but does not work. if I use id instead of all input types. his job.
but I want the generic code to set a placeholder for any text input fields on the page.
HTML:
<p>Login</p>
<input type="text" data-placeholder="Email" id="txtemail" />
<input type="password" data-placeholder="Password" id="txtpass" />
JQuery
foctext = $('input:text').attr("data-placeholder");
$(this).val(foctext);
$(this).focus(function () {
if ($(this).val() == foctext) {
$(this).val("");
}
});
$(this).blur(function () {
if ($(this).val() == "") {
$(this).val(foctext);
}
});
write the correct solution for this. thanks
source
share