shamim khan shamim khan - 2 months ago 5
Javascript Question

jquery placeholder text for input form

I'm using jquery placeholder text for a search placeholder. This search field doesn't have any placeholder so i added this text.

if(!$(this).val()) {
$(this).attr("placeholder", "Refine Your Search");

i don't know it's the best way to add a placeholder using jquery. If anyone know more simple way please add your code it will be very helpful.


You can directly set the placeholder no need to check value and use .each()

$('.mfilter-search input[type=text]').attr("placeholder", "Refine Your Search")

If you want to place on first then use

$('.mfilter-search input[type=text]:first').attr("placeholder", "Refine Your Search")