I have the following template in my markup.
<template id="unsequenced-template"> <button type="button" class="btn btn-primary railcar"></button> </template>
Then I insert it into my DOM like this.
// 在指定的目标之前,在无序列表中插入一个铁路车辆 function addSequenced(railcar, $target) { var $clone = $($('#unsequenced-template').html()); $clone.attr('data-id', railcar.id); $clone.text(railcar.number); $clone.insertBefore($target); modified = true; }
This method works, but there is no space between the inserted buttons. I even tried adding a space before $clone
but had no effect. I also tried adding spaces to the template but that didn't work either.
Some buttons are added at the beginning. They are one per line, with spaces shown between the buttons. But how to show space between buttons inserted using JavaScript?
Use flexbox to collapse all whitespace and add gaps.