Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show/hide an element in YUI as in jQuery?

Tags:

javascript

yui

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';
like image 948
Chad Johnson Avatar asked Dec 27 '10 20:12

Chad Johnson


2 Answers

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');
like image 180
Luke Avatar answered Nov 13 '22 00:11

Luke


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.

like image 24
Chad Johnson Avatar answered Nov 12 '22 23:11

Chad Johnson