开发者

YUI3 JavaScript: get CSS for placeholder text

I'm writing some JavaScript to implement placeholder text in browsers that don't have it.

I've successfully styled the placeholder text in Chrome 9 and Fx 4b11 using the following style rules:

::-webkit-input-placeholder { color: #969696 !important; }
input:-moz-placeholder { color: #969696 !important; }

Now I want my JavaScript to retrieve this data from the stylesheet in browsers that don't understand those rules so I can manually style the placeholder text.

Does anyone know how I can do that in YUI3? I tried:

YUI().use('node',function(Y) {
    var phColor = Y.all('::-webkit-input-placeholder').getStyle('color');
});

Unfortunately this just returns: "undefined: not bound to any nodes { _query="input::-webkit-input-placeholder", _nodes=}"

Anyone know how I can do this? Or if it's possible开发者_如何学编程?


If you aren't sold on using YUI exclusively (or are willing to harvest the jQuery code from a plugin and convert it to a YUI3 module) this jQuery plugin does exactly what you are trying to do: https://github.com/mathiasbynens/Placeholder-jQuery-Plugin

I've used it in a production environment and it works great even as far back as IE6 :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜