javascript - mootools: Creating a new DOM element from an HTML - Stack Overflow

How to create DOM elements from string (pass from ajax) in Mootools?In jQuery a simple solution is $( e

How to create DOM elements from string (pass from ajax) in Mootools?

In jQuery a simple solution is $( elements )

var elements = '<i>This is italic</i><b>this bold</b>...';

How to create DOM elements from string (pass from ajax) in Mootools?

In jQuery a simple solution is $( elements )

var elements = '<i>This is italic</i><b>this bold</b>...';
Share Improve this question edited May 28, 2013 at 17:12 Tiago Sippert 1,3307 gold badges24 silver badges33 bronze badges asked Jun 16, 2012 at 11:29 BogdanBogdan 1713 silver badges13 bronze badges 1
  • 1 mootools/blog/2010/03/19/a-better-way-to-use-elements – Andreas Commented Jun 16, 2012 at 11:47
Add a ment  | 

3 Answers 3

Reset to default 6

Simple as: Elements.from('<i>This is italic</i><b>this bold</b>')

Without a string, you would use the Element class:

var el = new Element('div#id.class', {
    text: 'My text',
});

With a string, you can check how it's one in Request.HTML, see here.

var temp = new Element('div').set('html', response.html);
response.tree = temp.childNodes;
response.elements = temp.getElements(options.filter || '*');

Basically Mootools elements & DOM elements are the same, this is another SO questions which creates DOM nodes from HTML: Creating a new DOM element from an HTML string using built-in DOM methods or prototype

From old Mootools forums, I found an interesting idea too: add a new method Element.fromString() or String.toElement() which would contain this logic.

I'm using the latest Mootools 1.6.0.
It throws Elements.from is not a function.

This one works for me:

var html = '<img src='+item.src+'>';
var el = new Element('li').set('html', html);

The working code: http://jsfiddle/chetabahana/qbx9b5pm/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745640523a4637662.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信