jQuery Append String vs Object Containing String

后端 未结 2 770
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-22 15:01

I understand that both of these will insert html into an element.

What are the differences between these 2 methods though?

String:

$(\"div\").app         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-22 15:35

    Is it just that you can do stuff like this?

    $("div").append($("

    ").html("Header"));

    Exactly

    Doing it this way creates for you a jQuery object which can further be manipulated with functions like append, css, addClass

    $("div").append($("

    ").html("Header") .addClass("someClass") .css("color", "gree"));

    Or if you don't want to do further manipulation like this, then by all means pass it just a string, and you'll get the same result.

提交回复
热议问题