i want the placeholder to be visible when we hover on the textbox.
<input type="text" placeholder="enter your name"/>
It's not possible to currently have the functionality built into the browsers, but with a small hack, it's possible:
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: transparent;
}
::-moz-placeholder { /* Firefox 19+ */
color: transparent;
}
:-ms-input-placeholder { /* IE 10+ */
color: transparent;
}
:-moz-placeholder { /* Firefox 18- */
color: transparent;
}
:hover::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: #999;
}
:hover::-moz-placeholder { /* Firefox 19+ */
color: #999;
}
:hover:-ms-input-placeholder { /* IE 10+ */
color: #999;
}
:hover:-moz-placeholder { /* Firefox 18- */
color: #999;
}
<input type="text" placeholder="Enter your name" />
Also note the browser compatibilities.
This is what I did using javascript. Hope it's what you're looking for:
Suppose your textbox's id is set to "input", then
input = document.getElementById('input');
function ph () {
input.setAttribute('placeholder','enter your name');
};
function phr () {
input.setAttribute('placeholder', '');
};
input.addEventListener("mouseover", ph);
input.addEventListener("mouseout", phr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With