Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .nothas?

Is there a way to do the equivalent of a .nothas() selector in jQuery? For example, if I wanted to add a TBODY to all TABLE elements that didn't already have one, it would be nice to do something like this:

$("TABLE").nothas("TBODY").append("<TBODY />");

It would be even better if this could be limited to direct descendents, so that (in this case) TABLE elements embedded in THEAD cells wouldn't be considered.

like image 676
Ken Paul Avatar asked Dec 11 '25 14:12

Ken Paul


1 Answers

jQuery has :not and :has selectors:

$("table:not(:has(tbody))").append("<tbody />");
like image 153
VisioN Avatar answered Dec 13 '25 09:12

VisioN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!