jQuery - Best Practice for creating complex HTML Fragments

后端 未结 9 1471
情深已故
情深已故 2021-01-30 03:21

Is there a general best practice for creating somewhat complex HTML elements in jQuery? I\'ve tried a few different ways.

First I tried using createElement and chaining

9条回答
  •  一整个雨季
    2021-01-30 03:50

    The way I am doing is shown bellow. I am not sure if u should create so many divs but it worked pretty well with me.

    var div1 = $('
    '); //THE COMPLEX DIV ITSELF var div2 = $('
    '); var div21 = $('
    '); var div22 = $('
    '); div2.append(div21); div2.append(div22); div1.append(div2); $("#df_background").append(div1); // ADDING the complex div to the right place

    Cheers,

提交回复
热议问题