Ciaran Archer
Ciaran Archer

Reputation: 12456

Prototype: wrapping raw HTML to create extended element

I am reading in a complex chunk of HTML and I'd love to be able to walk this sub-tree of HTML in the same way I can the DOM.

Is there a way in Prototype to take a raw chunk of HTML (say from an AJAX call) and 'wrap it' in some way so that it becomes a Prototype element and thus allow me to search it using .up() .down() etc?

Or do I need to add it to the DOM first before I can manipulate it in this way?

Thanks in advance.

Upvotes: 2

Views: 1071

Answers (2)

James
James

Reputation: 111960

var myDOMStructure = (new Element('div')).update(yourHTML);
myDOMStructure.down().down().up(); /// etc...

Upvotes: 5

Pekka
Pekka

Reputation: 449683

You could create a container element, give it an ID and put your complex HTML in it:

$('mydiv').update(complexHTML);

then you should be able to work through it like a DOM element.

Upvotes: 1

Related Questions