Insert html using jquery .html()

前端 未结 7 719
面向向阳花
面向向阳花 2021-02-08 15:58

I want to insert a large chunk of html into a pre-existing . I am using this method:

 $(\"td#content\").html(LOTS_OF_HTML_CODE_HERE);
         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-08 16:16

    I would suggest unifying the html into one string... like so.

    htmlStr = "";
    htmlStr += "

    some paragraph"; htmlStr += "

    another paragaraph

    "; $("#content").html(htmlStr);

    this way you can see where your html is breaking down and it adds a lot of readability to javascript created content.

    Also...

    if there is content in this TD that you'd like to keep, I would use the append() jquery method.


    the jquery documentation is your best friend!

提交回复
热议问题