Reputation: 1211
Because I can't add a placeholder
attribut at input
tag in my server code, so I need to use the jQuery to dynamically add this attribut when DOM is ready. So I write the following code, I tested it that works well in Chrome, Firefox and IE7, IE8, but it does't work well in IE9.
$(function () {
$('input').prop('placeholder', 'value');
}
Are there other jQuery methods can do this?
Yes, I know placeholder
is not support by IE9, and the jquery-placeholder
plugin was used in my pages, but this plugin need to check the placeholder
attr of input
tags, so I need to use jQuery
to add this attr, let this plugin to work.
Upvotes: 1
Views: 2974
Reputation: 10967
First try using .attr() function for jQuery, but Placeholders are not supported on IE.
$(function () {
$("input").attr("placeholder","Value");
}
But you can use this placeholder polyfill .
Upvotes: 1
Reputation: 903
I think question is duplicate and the answer is already mentioned here
Placeholder attribute not supported in IE. Any suggestions?
Upvotes: 0
Reputation: 3761
Yes, since placeholder
attr is not supported by all browser, you need a jQuery solution. You can use this plugin:
http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text
Hope it helps
Upvotes: 1