In jQuery, how to efficiently add lots of elements?

后端 未结 2 1995
执念已碎
执念已碎 2021-01-14 02:12

I currently have a sketch for a truthtable generator. While it works fine, it is rather slow. Each combination of boolean values I have added to a

2条回答
  •  再見小時候
    2021-01-14 02:59

    Try to avoid using .append in a loop, especially if you're adding a lot of elements. This is always a performance killer.

    A better option is to build up a string with the markup and do a single (or as few as possible) .append when your loop is finished.

    I see that you're using .data, which makes things a bit more complicated, but another option is to use the metadata plugin to attach structured markup to existing tags.

提交回复
热议问题