Reputation: 3661
Please take a look at this fiddle:
JQ-UI sets first option as default. I don't want it to be happened: instead I want to set HTML5 placeholder.
How can I set HTML 5 placeholder (instead of first available <option>
) for these JS generated inputs?
Upvotes: 5
Views: 25454
Reputation: 6834
This will do all you need without cross browser compatibility issue i have tested in ie7,8,9 runs perfect.
<input type="text" value="Search" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}">
good luck!
Upvotes: 2
Reputation: 36594
Use:
input.attr("placeholder", value);
Updated jsfiddle:
http://jsfiddle.net/Meligy/KA85s/5/
In the example I just replaced your val()
call, obviously, you can completely remove the part from the function and add it separately with any text you want.
Upvotes: 3
Reputation: 6916
@Mohamed Meligy came with the same solution
Though i used something else..
here is how it works when your input element is created with use jQuery to give it a placholder attribute and we are done :D
** UPDATED **
added custom default value :D
Upvotes: 1