开发者

How to detect and list all unique class-names (and ids) inside an .erb file?

I want to detect and prepare a list of unique class names that are being used inside a given view. Is there a way to do it, apart from manual Ctrl+F search i开发者_开发百科n Aptana/Rubymine?


If you are using jQuery, you can

$.unique($('*').map(function(i, e){return $(e).attr('id')}))

and for classes

$.unique($('*').map(function(i, e){return $(e).attr('class').split(' ')}))

Note that the jQuery documentation at http://api.jquery.com/jQuery.unique/ says that "unique()" does only work on jQuery objects but we are using it here with strings. I just tried it on the stackoverflow site though and it seems to work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜