Saturday, June 15, 2013

Get an element by id in Dojo 1.9 and also find the ids of the elements within it.

Using underscore.js with Dojo, I herein put the id monikers of all of the tagged items within foo into an array called kids and then I just do nothing with the array:

<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1,maximum-
            scale=1,minimum-scale=1,user-scalable=no"/>
      <meta name="apple-mobile-web-app-capable" content="yes" />
      <title>Whatever</title>
      <link rel="stylesheet" type="text/css" href="styles.css" media="screen">
      <style type="text/css" media="all">
         section {
            height: 40px;
         }
      </style>
   </head>
   <body style="overflow-y:hidden; overflow-x:hidden;">
      <article id="foo">
         <h1>FOO</h1>
         <section id="bar">BAR</section>
         <section id="baz">BAZ</section>
         <section id="qux">QUX</section>
      </article>
      <script src="underscore-min.js" data-dojo-config="async: true"></script>
      <script src="dojo/dojo.js" data-dojo-config="async: true"></script>
      <script type="text/javascript">
         require(["dojo/dom", "dojo/domReady!"], function(dom) {
            var foo = dom.byId("foo");
            var kids = new Array();
            _.each(foo.childNodes, function(node) {
               if (node.id != undefined && node.id != "") {
                  kids.push(node.id);
               }
            });
         });
      </script>
   </body>
</html>

No comments:

Post a Comment