开发者

Prototype: wrapping raw HTML to create extended element

开发者 https://www.devze.com 2022-12-10 02:16 出处:网络
I am reading in a complex chunk of HTML and I\'d love to be able to walk this sub-tree of HTM开发者_如何学PythonL in the same way I can the DOM.

I am reading in a complex chunk of HTML and I'd love to be able to walk this sub-tree of HTM开发者_如何学PythonL 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消