最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I showhide an element in YUI as in jQuery? - Stack Overflow

programmeradmin0浏览0评论

In jQuery, when I want to show or hide something, I do this:

$('#elementId').show();
$('#elementId').hide();

How do I do this with YUI? I've tried YAHOO.util.Dom.get('elementId').hide(), asked my co-workers, looked at the documentation, and searched Google, and I've found nothing helpful. From the documentation, it looks like this should work

YAHOO.util.Dom.get('elementId').setStyle('display', 'none')

but of course it does not. All I can think of is this, which sucks because then I'm not using a framework:

document.getElementById('elementId').style.display = 'none';

In jQuery, when I want to show or hide something, I do this:

$('#elementId').show();
$('#elementId').hide();

How do I do this with YUI? I've tried YAHOO.util.Dom.get('elementId').hide(), asked my co-workers, looked at the documentation, and searched Google, and I've found nothing helpful. From the documentation, it looks like this should work

YAHOO.util.Dom.get('elementId').setStyle('display', 'none')

but of course it does not. All I can think of is this, which sucks because then I'm not using a framework:

document.getElementById('elementId').style.display = 'none';
Share Improve this question asked Dec 27, 2010 at 20:51 Chad JohnsonChad Johnson 21.9k36 gold badges115 silver badges216 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 15

You can omit the Dom.get.

YAHOO.util.Dom.setStyle('elementId', 'display', 'none');

FYI, in YUI 3 (as of 3.3.0pr3)

Y.one('#elementId').hide();

For YUI 3.2-

Y.one('#elementId').setStyle('display', 'none');

Apparently I have to do this:

YAHOO.util.Dom.setStyle(YAHOO.util.Dom.get('elementId'), 'display', 'none');

Ridiculously and unnecessarily long, but it seems to work.

发布评论

评论列表(0)

  1. 暂无评论