how to use attributes within a javascript function


I have a javascript function to which I pass a parameter, and within that function I want to modify an attribute of that parameter, but I do not get it. My code is as follows:

This is the code from which I call my function (which is a dialog box)

mostrarDialogoBorrar([[#{dialogo_confirm_borrar_indice}]], nombreCampo);

This is my function that shows the dialog box, which has two buttons. When I select one of the buttons I want to change the checked attribute of the checkbox that has id = fieldname

function mostrarDialogoBorrar(texto, nombreCampo){
     alert( $(  "#nombreCampo" ));
     $( "#dialog-confirm-generic" ).dialog({
         resizable: false,
         modal: true,
         position: [($(window).width() / 2) - 150, 300],
         dialogClass: 'DeleteConfirmDialog',
         buttons: {                                 
             [[#{dialogo_confirm_table_button_continuar}]]: function() {
                 $( this ).dialog("close");
             [[#{dialogo_confirm_delete_button_cancelar}]]: function() {
                 $( '#' + nombreCampo ).attr('checked', true);
                 $( this ).dialog("close");


The line that does not work is the following:

$( '#' + nombreCampo ).attr('checked', true);
asked by cucurril 11.04.2016 в 11:45

2 answers


Already this, I just had to change the line that gave problems for:

answered by 11.04.2016 / 11:53

In Jquery, according to the version, it could be something like this:

$( '#' + nombreCampo ).prop("checked", true);
answered by 11.04.2016 в 12:02