Why does call to jQuery's appendChild fail with undefined error?

前端 未结 3 1137
鱼传尺愫
鱼传尺愫 2021-01-12 03:02

Here is my simple HTML:


    
Hello World!

Here is

相关标签:
3条回答
  • 2021-01-12 03:10

    .appendChild() is a plain JavaScript method, not jQuery. The jQuery method is .append().

    newDiv.append(newSpan);   
    $( myDOMElement ).append(newDiv);
    
    0 讨论(0)
  • 2021-01-12 03:12

    Use .append()

    newDiv.append(newSpan); 
    

    .appendChild() works with DOM element. newDiv is jQuery Object not a plain JavaScript DOM element.

    Working Fiddle

    0 讨论(0)
  • 2021-01-12 03:26

    newDiv is a jQuery object, not a DOM object.

    jQuery objects do not have an appendChild method, they have an append method.

    0 讨论(0)
提交回复
热议问题