You can use the Element.From that Aaron showed, thats is more reliable or
use your function that won't work for some elements (table elements).

var create_dom = function(html){
    var tempDiv = new Element('div', {html: html});
    var firstElement = tempDiv.getFirst();
   tempDiv.destroy();
   return firstElement;
}

This might work and remove will temporary div.

--
Fábio Miranda Costa
Solucione Sistemas
Front-End Engineer
http://meiocodigo.com


On Sun, Sep 13, 2009 at 11:55 PM, Aaron Newton <aa...@iminta.com> wrote:

> this will be in the next release of mootools more, but you can use it now
> (just add it to your javascript):
>
> http://github.com/mootools/mootools-more/tree/master/Source/Element/Elements.From.js
>
> the raw file:
>
>
> http://github.com/mootools/mootools-more/raw/master/Source/Element/Elements.From.js
>
>
> On Sun, Sep 13, 2009 at 7:24 PM, limodou <limo...@gmail.com> wrote:
>
>>
>> 2009/9/13 Fábio M. Costa <fabiomco...@gmail.com>:
>> > In this case you could use Request.HTML. It would give you an li node
>> and
>> > you would just do:
>> >
>> > target.grab(response.elements, 'top');
>> >
>> > http://mootools.net/docs/core/Request/Request.HTML
>> >
>> > Both the ways you showed are fine, but i would do number 2 just because
>> its
>> > faster.
>> >
>> > Still you could do number 1 in a shorter way:
>> >
>> > var item = new Element('li', {html: response.html});
>> > target.grab(item, 'top);
>> >
>> > As the second parameter of the Element constructor you can pass an
>> object
>> > with any property that you can use with the 'set' method from Element
>> > (styles, events, html ....).
>> >
>> > Cya.
>> >
>>
>> In Jquery, you can $('<li>A Test</li>') to create a DOM element, so is
>> there a similar way to do that?
>>
>> Why I can't use Request.HTML, because I need also other information,
>> for example, I need:
>>
>> {'success':true, 'message':'ok', 'html':'<li>A Test</li>'}
>>
>> and for the second way, I also need to reget the new element from the
>> container, for example:
>>
>> <div id='target'></div>
>>
>> var target = $('target');
>> target.set('html', response.html + target.get('html'));
>> var el = target.getFirst();
>>
>> But if I can :
>>
>> var el = xxx(response.html);
>> var target = $('target');
>> target.grab(el, 'top');
>>
>> I think this will be better.
>>
>> Or I can do this:
>>
>> var empty = new Element('div');
>> empty.set('html', response.html);
>> var el = empty.getFirst().clone();
>> empty.dispose();
>>
>> --
>> I like python!
>> UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
>> UliWeb <<simple web framework>>: http://uliwebproject.appspot.com
>> My Blog: http://hi.baidu.com/limodou
>>
>
>

Reply via email to