user3532637 user3532637 - 2 months ago 6
jQuery Question

Search and replace input placeholder text with jQuery

How can I search and replace placeholder text from all input boxes?

Example: I wanna change

<input type="text" name="user" id="user" placeholder="User">


to

<input type="text" name="user" id="user" placeholder="Benutzer">


By something like that

$('input').each(function() {
$(this).attr("placeholder").replace('User', 'Benutzer');
});


Thanks and best regards!

Answer

Target elements based on the attribute, then change it

$('input[placeholder="User"]').attr('placeholder', 'Benutzer')