开发者

jQuery not able to retrieve placeholder attribute value?

Is there a jQuery way for me to retrieve the placeholder attribute of a form input element? I've tried the obvious:

alert($('form_input_element').attr('placeholder'));

but it returns undefined in both firefox and chrome for so开发者_开发技巧me reason! All other attributes are displayed fine with the above code... is this a bug in jQuery? using the latest version. Is there a workaround?

UPDATE: Ok, very surprisingly another jQuery plugin was actually REMOVING the placeholder attributes on all input elements... That's why I was getting undefineds.


I think the problem is that your selector may match more than one input, and the first one of your collection has no placeholder attribute defined like in this example

http://jsfiddle.net/fcalderan/rmN7J/

so be sure that your selector returns one input or all of your inputs selected have placeholder attribute defined


Is form_input_element a class name? If so, you need a . in front of it. (ie $(".form_input_element"))

If it's an id, then you need the # in front of it. (ie $("#form_input_element"))

Remember that the string you pass to the jQuery object is virtually identical to a CSS selector, so it must be formatted as such. Currently, your selector is looking for an element named form_input_element which does not exist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜