Is there a way to add a placeholder attribute (placeholder tag, not “defaultvalue” and similar approaches) if you have an text input field that has “value” property empty?
I have seen many similar questions here, but most of them use defaultvalue. I need placeholder tags and additionally I can’t influence HTML output at all.
This is the given HTML output example:
<input type="text" value="" name="textbox" id="edit-textbox">
I’d suggest any one of the following approaches:
JS Fiddle demo using
el.placeholder = 'placeholdertext'.JS Fiddle demo using
el.placeholder = $('label[for=' + el.id + ']').text().Or you could use an array to store the various placeholders:
JS Fiddle demo.
To specify a particular placeholder for a particular element:
JS Fiddle demo.
Added a catch/fall-back in the event that an entry doesn’t exist in the placeholders object for a particular
input:JS Fiddle demo.