Search code examples
prototypejs

How get html of div by class name on prototype


I am before work in JQuery and i am a little don't understood how i can get <a>asd</a> of .quote_content on prototype

<div class="quote_content">
     <a>asd</a>
</div>

Thanks!

UPDATE

I have a function which do that:

<script type="text/javascript">// <![CDATA[
function showCompare() {
    var quote_content = $$(".quote_content");
    win = new Window({className: "mac_os_x", title: "Sample", width:800, height:400, destroyOnClose: true, recenterAuto:false});

    win.getContent().innerHTML = quote_content;
    win.showCenter();
}
// ]]></script>

But quote_content output is [object HTMLDivElement]


Solution

  • Try this, if all you want to do is go through a page finding any element with the classname quote_content and return its HTML content:

    $$('.quote_content').each(function(elm){
      // do whatever you like with elm.innerHTML
      alert( elm.innerHTML );
      // note that any whitespace, as in your example
      // will be preserved. You may prefer this instead:
      var child = elm.down();
      alert( child.outerHTML );
      // this only works if you know there is only one
      // child element, though
    });