Changing the "placeholder" attribute of HTML5 input elements dynamically using Javascript

cemregr picture cemregr · Oct 12, 2010 · Viewed 75.3k times · Source

I'm trying to dynamically update the HTML5 placeholder attribute of a text field using jQuery.

$("textarea").attr("placeholder", "New placeholder text");

From Firebug, I can observe that the placeholder attribute is indeed changing. But in the rendered textarea element, it stays the same. Any suggestions?

Answer

tilak picture tilak · Oct 25, 2012

try this :

$('#inputTextID').attr("placeholder","placeholder text");