How to hide a row depending on the text you have, jquery?

0

Currently I fill a table dynamically in the following way:

var formas_pagos = $('.formas_pagos');
var input_cantidad ="";
var text_forma_pago = "";
$.each(response.data, function(index,value){
    console.log(value.disponible);
    if (value.disponible === 0){
        input_cantidad = '<input type="number" step="0.01" name="cantidad" class="cantidad" min="1" pattern="^[0-9]+" placeholder="Cantidad" disabled="true">';
    }
    else{
        input_cantidad = '<input type="number" step="0.01" name="cantidad" class="cantidad" attr-num-doc="' + value.forma_pago + '" min="1" pattern="^[0-9]+" placeholder="Cantidad">';
    }
    $('<tr>')
        .append($('<td/>').addClass('nuevo-td nombrePago').text(value.forma_pago))
        .append($('<td/>').addClass('nuevo-td cantPago').text(value.disponible.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')))
        .append('<div class="cod_forma_pago" style="display:none">' + value.cod_forma_pago + '</div>')
        .append('<div class="cod_banco" style="display:none">' + value.Cod_Banco + '</div>')
        .append('<div class="monto_pago" style="display:none">' + value.monto_pago + '</div>')
        .append($('<td/>').addClass('label-cell nuevo-td')
            .append($('<label/>').addClass('label-checkbox item-content')
                        .append('<input type="checkbox" name="tipo_pago" class="tipo_pago derecha" attr-num-doc="' + value.forma_pago + '" value="' + value.disponible + '"/>')
                        .append($('<span/>').addClass('item-media').append('<i class="icon icon-form-checkbox"></i>'))))
        .append($('<td/>').addClass('label-cell classCantidad derecha')
                            .append(input_cantidad))
        .appendTo(formas_pagos);
});
if (tipo_envio === "2" && $('.nombrePago').text() === "Efectivo"){
    $('.nombrePago').hide();
}

but I need to hide the row that contains in the class .nombrePago the text "Effective". Try as follows:

if (tipo_envio === "2" && $('.nombrePago').text() === "Efectivo"){
    $('.nombrePago').hide();
}

but it did not work for me. Visually, this is the table:

Thank you in advance.

    
asked by JG_GJ 20.10.2018 в 06:55
source

1 answer

0

I had to add the following line:

if (tipo_envio === "1"){
   $('.formas_pagos').find('td:contains("Efectivo")').parent().toggle();                  
}
    
answered by 20.10.2018 в 07:56