jQuery document.createElement equivalent?

后端 未结 14 1701
暖寄归人
暖寄归人 2020-11-22 05:41

I\'m refactoring some old JavaScript code and there\'s a lot of DOM manipulation going on.

var d = document;
var odv = d.createElement(\"div\");
odv.style.di         


        
14条回答
  •  粉色の甜心
    2020-11-22 06:02

    It's all pretty straight forward! Heres a couple quick examples...


    var $example = $( XMLDocRoot );
    

    var $element = $( $example[0].createElement('tag') );
    // Note the [0], which is the root
    
    $element.attr({
    id: '1',
    hello: 'world'
    });
    

    var $example.find('parent > child').append( $element );
    

提交回复
热议问题