'How to find element from html with jQuery
I have a table with checkbox option for each row.
For each row I have href (dedicated link) handled by HTML file.
I have created a button called: "download" by JS, and I want to define this button to save all the links for the rows which have selected in the checkboxes, and save it in one variable, selectedLinks = []
Any idea how can i fix my JS function.
//function download button
$(document).on("click", "#downloadBtn", function() {
console.log("download button click")
var selectedLinks = []
$('.last')
.checkSingel("checkSingle")
.forEach(function(record) {
if (record.checked) {
//selectedLinks.push(record.href)
alert($(this).attr("href"));
}
})
console.log(selectedLinks)
});
</td>
<td class="last"><a style="font-weight:bold;text-decoration:underline;" href="/download/{{ elements.EvidencePath }}">Click here to download Evidence</a>
</td>
Solution 1:[1]
this is the proper code :
// function to add multiple check box for all rows
$(document).on("click", ".checkAll", function(){
$('input:checkbox').not(this).prop('checked', this.checked);
// this statement is checked it will enable the download button ( for check all button)
if(this.checked) {
$(".dt-buttons a:last-child").removeAttr("disabled");
}else {
$(".dt-buttons a:last-child").attr("disabled", "disabled");
}
});
// this statement is checked to eanbled the button if the checkbox checked. ( for check single button)
$(document).on("click", ".checkSingle", function(){
if(this.checked) {
$(".dt-buttons a:last-child").removeAttr("disabled");
}else {
$(".dt-buttons a:last-child").attr("disabled", "disabled");
}
});
//function download button
$(document).on("click", "#downloadBtn", function(){
console.log("download button click")
var selectedLinks = []
$('.last').checkSingel("checkSingle").forEach(function(record){
if (record.checked){
//selectedLinks.push(record.href)
alert($(this).attr("href"));
}
})
console.log(selectedLinks)
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ROIR |