Good day.

Tell me how to write the correct condition for selectorName: there is a table, if it contains 50% of the information, then paint it in white.

$(document).ajaxComplete(function() { var raws = $("[data-tr-classes=' realty-raw ']"); $.each(raws, function (index, value) { if ($(value).parent().parent().find('сюда нужно вставить наш selectorName') { $(this).parent().parent().css('background-color', '#FFF'); } }); }); 
  • one
    How is information filled in? - Grundy
  • if ($ (value) .parent (). parent (). find ('td'). text ()! == '') can be like this, but how to make a condition in which if 50% td is not empty? - ultimatum
  • what does 50% td mean not empty? ? - Grundy
  • Well, it is stupid to calculate the number of TDs empty in TR and calculate the percentage using the formula, but here not only the selector is needed, but also, for example, the function of calculating the percentage. - Dmitriy Gvozd
  • There is a data selection table in the project, with different roles: “raw” classes = 'realty-raw' colors gray and does not work correctly, the task is to correct “raw” in jQuery -> if this tr (strings) is filled more 50% td repaint tr (whole line) white - ultimatum

2 answers 2

The problem is solved in one line of the condition, without taking into account the check of division by 0:

 if($('td:empty').length / $('td').length >= 0.5) { // Тут ваше действие. } 

Selector :empty selects elements that do not have child nodes, including text nodes.

    A little finalized through :not(:empty)

    The function finds the string ( tr ), counts the number of non-empty elements and if it is more than 50% colors in #FFF

     $(document).ajaxComplete(function() { var raws = $("[data-tr-classes=' realty-raw ']"); $.each(raws, function (index, value) { if ($(value).parent().parent().find(('td:not(:empty)').length / $('td').length >= 0.5)) { $(this).parent().parent().css('background-color', '#FFF'); } }); });