Frage

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]

War es hilfreich?

Lösung

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
});

Andere Tipps

First you need to know is class attribute is identify it with a point after the class name, in you'r case .quote_content then you must go for the child element, I know 2 ways to do that.

1-

$('.quote_content > a')

2-

$('.quote_content').children("a")

or if the child element have a class:

1-

$('.quote_content > .child_element_class')

2-

$('.quote_content').children(".child_element_class")
function showCompare() { 
  var quote_content = document.getElementById('quote_content'); 
  console.log(quote_content); 
  win = new Window({className: "mac_os_x", title: "Sample", width:800, height:400, destroyOnClose: true,   recenterAuto:false});

  win.getContent().innerHTML = quote_content.innerHTML; 
  win.showCenter(); 
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top