Appending multiple html elements using Jquery

后端 未结 5 1999
醉话见心
醉话见心 2021-02-08 02:10

Am new to jQuery and wondering if any could advise me on best practise...

I am looking to append a div element to the page, which contains a lot of html and not sure wha

5条回答
  •  北海茫月
    2021-02-08 02:52

    If you want to add the HTML as it is, then just use the jQuery append function. For example:

    $('body').append('
    
    \

    This is the test

    \

    Hello, just a test

    \ Click me\ Click me again\
    ');

    Change the selector from body to other DOM element/selector according to your requirement.

    Or if you already have the div element with ID "test" in the document, then you can set the content using the html() function like below:

    $("#test").html('

    This is the test

    \

    Hello, just a test

    \ Click me\ Click me again');

提交回复
热议问题