views:

34

answers:

2

Is there any way to create HTML markup in YUI like:

<div id={DivId}>
 <p class={pClass}>
  <span class={spanClass}> {Content} </span>
 </p>
</div>
A: 

I don't think so. At least not exactly. The more JavaScript like way is by manipulating the DOM elements. For example:

  <body>
    <div id="my-div">
     <p id="my-p">
      <span id="my-span></span>
     </p>
    </div>

   <script>
YUI().use('node', function(Y) {
  Y.one("#my-div").set("id", "my-new-div-id");
  Y.one("#my-p").addClass("a-paragraph-class");
  var mySpan = Y.one("#my-span");
  mySpan.addClass("a-span-class");
  mySpan.set("innerHTML","My span content.");
});
   </script>

Of course this is a bit of overkill for your application. However there's a lot more you can do with YUI3 nodes than this.

John

mjhm
+1  A: 

If I understand your question correctly, Y.substitute might be worth looking at.

If you haven't seen it, I'd recommend watching through the YUI 3 Sugar video at the YUI theater. Jump to 22:27 for more on Y.substitute.

Lauri Lehtinen