Create HTML element with YUI

萝らか妹 提交于 2019-12-12 13:47:08

问题


I am using following code to create a html element in the page body with using YUI. This code doesn't produce any error.

The issue is, the paragraph element is not created in the html page.

<html>
    <head>
        <title>YUI Test</title>
        <meta charset="UTF-8">
        <script src="http://yui.yahooapis.com/3.14.1/build/yui/yui-min.js"></script>
        <script>
            // Create a YUI sandbox on your page.
            YUI().use('node', function(Y) {
                // Create DOM nodes.
                var contentNode = Y.Node.create('<p>');

                contentNode.setHTML('This is a para created by YUI...');
            });           
        </script>
    </head>
    <body>
        <h1>Page body section...</h1>

    </body>
</html>

回答1:


The node is created, but it is also detached from the DOM. You have to attach it to the DOM by using either

Y.one('body').append(contentNode);

or

contentNode.appendTo(Y.one('body'));

or

Y.one('nav.main-navigation').insert(contentNode, 'before');

or any of the other methods for manipulating dom in YUI.



来源:https://stackoverflow.com/questions/21312900/create-html-element-with-yui

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!