Parses an HTML string into an HTML document object that supports CSS selectors. Pass mode "fragment" to parse the markup as a fragment, "document" to force full-document parsing, or omit it to auto-detect (strings that look like a full document are parsed as documents, everything else as a fragment). The returned object exposes select(selector), selectWithin(element, selector), attr(element, name), setAttr(element, name, value), hasAttr, removeAttr, text, innerHTML, outerHTML, tagName, allElements and documentHTML()/toString() to serialise back to HTML.
htmlDocument(html [, mode])
→ returns any
fragmentdocumentParse a fragment and pull out the class of every .item element.
doc = htmlDocument("<ul><li class=\"item\">one</li><li class=\"item\">two</li></ul>");
items = doc.select(".item");
for (i in items) {
writeOutput(doc.attr(items[i], "class") & " ");
}
Expected Result: item item
Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.