Vì vậy, tôi thấy ở đây ra add a div và tại đây cách add a class nhưng tôi gặp sự cố khi kết hợp cả hai. Tôi muốn tạo ra một bó toàn bộ các div của một lớp và id cụ thể trong div sparkLineContainer.jquery, thêm div với định nghĩa lớp
Tôi có div chứa
<div id="#sparkLineContainer"></div>
và tôi muốn thêm một loạt các nội dung sau để nó
<div id="#sparkLineContainer">
<div class="sparkLines" id="id1">Some stuff here</div>
<div class="sparkLines" id="id2">Some stuff here</div>
<div class="sparkLines" id="id3">Some stuff here</div>
// and so on
</div>
đoạn - Tôi không làm cho nó rất xa, tôi stumped
$('#sparkContainer').add("div"); \\ How do I add the id and class to this div?
\\ And as a repeat the function will it overwrite this?
Hàm tôi đang cố thực hiện việc này.
function renderSparklines (array1, sparkLineName, id) {
// array1 is the data for the spark line
// sparkLineName is the name of the data.
// Turn all array values into integers
arrayStringToInt(array1);
// Create new div of class sparkLines
$('#sparkContainer').add("div")
// Render new spark line to
$('.sparkLines').sparkline(array1, {width:'90px'});
var htmlString = ""; // Content to be added to new div
// GENERATE LITTLE SPARK BOX
htmlString +=
'<font class = "blueDescriptor">' + sparkLineName + '</font>'+
'<br>'+
'<font class = "greyDescriptorSmall">Ship to Shore</font>'+
'<br>'+
'<font class = "blackDescriptorSparkLine">' + array1[array1.length-1] + '</font>'+
'<font class = "greenDescriptorSparkline">(' + (array1[array1.length-1] - array1[array1.length-2]) + ')</font>' +
'<br>';
$('.sparkLines').prepend(htmlString);
}
.add() chức năng không thêm của một div. Nó chỉ thêm vào bộ chọn phù hợp. –