0

I have some a table and I need to keep only few contents in this table, so I have this

 $(truc).find('tr').each(function(lig) {
        if (lig != 0 && (!$(this).children(':first').not('')) && (!$(this).children(':first').hasClass('main-title')) && (!$(this).children(':first').hasClass('top-top-title'))) {
            $(this).remove();
        }
        ;
    }

I need help for the (!$(this).children(':first').not('')) because I need to select the line where the first child has no class(not even an empty class) and I don't know which instructions I need

Edit : I resolved myself witch a check on $(this).children(':first') if they have an attribute class $(this).children(':first').attr('class'), so if an element has no class, it doesn't enter in the if

mehdi lotfi
  • 11,194
  • 18
  • 82
  • 128
Valinor
  • 13
  • 7
  • this is my var with the table inside – Valinor Jun 04 '13 at 10:01
  • 4
    possible dublicate: http://stackoverflow.com/questions/1962247/jquery-get-all-divs-which-do-not-have-class-attribute – Dirty-flow Jun 04 '13 at 10:01
  • Dirty flow has already given the answer to your question.. – writeToBhuwan Jun 04 '13 at 10:02
  • You can get class attribute and compare it to ''. Just iterate through children. – zozo Jun 04 '13 at 10:03
  • I already saw this question, but I don't know how to use the answers, or they don't work, I tried $(this).children(':first').not('class'); $(this).children(':first').not('[class]'); $(this).children(':first').not([class]), same results – Valinor Jun 04 '13 at 10:13
  • @Valinor what are the cases you want to check? – Arun P Johny Jun 04 '13 at 10:20
  • Thanks for helping me, but I found a similar solution : I check on my $(this).children(':first') if they have an attribute class <<<< $(this).children(':first').attr('class') >>>>> , so if an element has no class, it doesn't enter in the if. – Valinor Jun 04 '13 at 10:23
  • @Valinor add your solution as answer, it could be useful for other users – Dirty-flow Jun 04 '13 at 13:52

2 Answers2

0

Try

!$(this).children(':first').get(0).className
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

Check for the attribute, like this

(!$(this).children(':first').not('[class]'))
BrunoLM
  • 97,872
  • 84
  • 296
  • 452