Dynamize language for placeholder

Posted on

Question :

I do an ajax request to fetch in the database to bring the language configuration, type, PT-BR, EN, and so on …

I want the placeholders to be changed according to the chosen language. For example, instead of being placeholder='Digite seu usuario' , I’d like you to placeholder='Enter your username' and so on …

For block type tags (type p, div etc.) I handle $("#memberArea").html(data.pt.member_area); , and then it works perfectly, however, for placeholder I do not know …

Is there any way to manipulate this via jQuery?


Answer :

Yes. placeholder is an attribute of the element. You can then change it:

function teste() {
	$("#teste").attr("placeholder","Enter your username");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputplaceholder="Digite seu usuario" type="text" id="teste" />
<input type="button" value="alterar placeholder p/ inglês" onclick="teste()" />


Leave a Reply

Your email address will not be published. Required fields are marked *