I'm using readability's code to extract HTML from a web page. How do I display it on a page?
$content = grabArticle($webpage);
echo $content;
ERROR => Object of class DOMElement could not be converted to string...
The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object. In the Console, get the element and assign it to the demoId variable. Logging demoId to the console will return our entire HTML element.
The HTML DOM can be accessed with JavaScript (and with other programming languages). In the DOM, all HTML elements are defined as objects. The programming interface is the properties and methods of each object. A property is a value that you can get or set (like changing the content of an HTML element).
Document object model. The DOM is the way Javascript sees its containing pages' data. It is an object that includes how the HTML/XHTML/XML is formatted, as well as the browser state. A DOM element is something like a DIV, HTML, BODY element on a page.
With display:none, it is effectively removed from the DOM. Hiding DOM elements with CSS is a common task. Some wonder whether they should use visibility:hidden or display:none.
Marc B's answer got me on the right track, but I had a similar need and this was the code I landed on:
$newdoc = new DOMDocument;
$node = $newdoc->importNode($node, true);
$newdoc->appendChild($node);
$html = $newdoc->saveHTML();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With