Jair
Jair

Reputation: 1211

Add input attribute with jQuery prop no work in IE9

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?

Update:

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

Answers (3)

Rosmarine Popcorn
Rosmarine Popcorn

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

Anna.P
Anna.P

Reputation: 903

I think question is duplicate and the answer is already mentioned here

Placeholder attribute not supported in IE. Any suggestions?

Upvotes: 0

mario595
mario595

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

Related Questions