How do I assemble a
    using jQuery append()?

后端 未结 5 1396
谎友^
谎友^ 2020-12-29 20:17

I\'m trying to use the append function and encountered this:

$(\"#details\").append(\'
    \'); for (var i = 0; i < 10; i++) { $(\"#details\").ap
5条回答
  •  轮回少年
    2020-12-29 21:00

    No, it's a programmer bug.

  • s are attached to their
      or
        , not to its container. And appending a close tag is nonsensical.

        You're basically working as if what you were appending were raw HTML, and it's not; you're actually working with the DOM.

        Try this:

        var list = $("#details").append('
          ').find('ul'); for (var i = 0; i < 10; i++) list.append('
        • something
        • ');

          Note: please see (and upvote) Blixt's answer, which expands on a couple different options that are superior for various purposes. It deserves attention and hasn't been getting it.

    提交回复
    热议问题