jQuery - Appending a div to body, the body is the object?

后端 未结 6 1775
無奈伤痛
無奈伤痛 2020-12-28 11:58

When I\'m adding a div to body, it\'s returning the body as the object and then whenever I use that - it\'s obviously using body. Bad.

Code:-

var hol         


        
6条回答
  •  北海茫月
    2020-12-28 12:31

    jQuery methods returns the set they were applied on.

    Use .appendTo:

    var $div = $('
    ').appendTo('body'); $div.attr('id', 'holdy');

提交回复
热议问题