Tengo una tabla con opción de casilla de verificación para cada fila.
Para cada fila tengo href (enlace dedicado) manejado por archivo HTML.
He creado un botón llamado: "descargar" por JS, y quiero definir este botón para guardar todos los enlaces de las filas que se han seleccionado en las casillas de verificación y guardarlo en una variable, enlaces seleccionados = []
¿Alguna idea de cómo puedo arreglar mi función JS?
//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>este es el codigo correcto:
// 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) });