Search code examples
javascriptgoogle-closure-library

confusing google closure library api


could someone explain to me how the Closure works in more user-friendly form? Its help and documentation leads me nowhere really. How do you perform a simple task such as selecting and modifying the dom (e.g. select all on page and hide them)?


Solution

  • See http://derekslager.com/blog/posts/2010/06/google-closure-introduction.ashx, Comparison #4,

    Hide all div's:

    <html>
    <head>
    <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js" type="text/javascript"></script>
    <script language="JavaScript">
      goog.require('goog.dom.query');
      goog.require('goog.style');
    </script>
    <script> 
      function HideElement(selector) {
        goog.array.map(goog.dom.query(selector, null), function(e) { 
            goog.style.showElement(e, false); 
        });
      }
    </script>
    </head>
    <body>
       <div>div</div>
       <p>paragraph</p>
       <div>another div</div>
       <input type="button" value="hide" onclick="HideElement('div');"/>
    </body>
    </html>
    

    Can't help you with the user-friendly breakdown, though.