How do I force jQuery append to NOT automatically close a tag?

前端 未结 3 1387
借酒劲吻你
借酒劲吻你 2020-11-30 11:07

I have a JavaScript object with about 1000 properties and want to create a

of these entries, with eight properties in a single row,
3条回答
  •  离开以前
    2020-11-30 11:31

    Seven years, but I tought I could help anyone else that comes across a similar problem. For example, if you want to use JQuery's $.each() with .append() to make an list of users, such as:

    • User 1
    • User 2

    Here's what you DON'T want to do:

    element.append(`
      `); $.each(users, function(key, value) { element.append(`
    • ${value.name}
    • `); }); element.append(`
    `);

    The output will be something like:

    • User 1
    • User 2
    • Instead, here's what you WANT to do:

      element.append(`
        `); $.each(users, function(key, value) { $("#ul-users").append(`
      • ${value.name}
      • `); });

        So the output will be as follows:

        • User 1
        • User 2

      提交回复
      热议问题