I want to capture a group of tables that have more than X rows with jQuery. I am currently doing something similar to:
$("table").each(function(){ if($(this).find("tr").length > x){ tableArray[tableArray.length] = $(this); } });
and then acting on the tableArray elements.
Is there a better way to get these tables, maybe a good selector that I missed?
thank
Try using the :hasselector:
:has
$('table:has(tr:eq('+x+'))');
x. , :eq() , , x 1, , 2 , .
x
:eq()
EDIT :has , :nth-child :eq. .has() ( ) :
:nth-child
:eq
.has()
alert($('table').has("tr:nth-child(2)").length)
, , , nth-child, , :eq.
nth-child
- .
http://api.jquery.com/nth-child-selector/
$("table tr:nth-child(" + (x + 1) + ")").parent();
, . : ".parent()" .
I think your path is fine, to be honest.
One alternative way would be to use a selector in conjunction with : ask jQuery for . This says "find all tables whose elements have 4 or more children." Since child elements are usually elements, this will do the trick. :has nth-child$("tbody:has(:nth-child(4)))...tbodytbodytr
$("tbody:has(:nth-child(4)))...
tbody
tr
Source: https://habr.com/ru/post/1749773/More articles:How to quickly, smoothly scroll using UIWebView? - iphoneРеализация CATiledLayer в UIWebView для быстрой прокрутки - iphoneNSEntityDescription entityForName returns zero - iosClass Testing - genericsПолучение Gowalla История регистрации с использованием API - apiis there any way to provide a 30 second limit on the local devengine server? - pythonPHP - PRE-select drop down option - phpThe Qt4 book says: “Make a release,” reality disagrees - debuggingExtract a specific string from curl'd result - bashAgilent E4426B Signal Generator Locks During Multiple GPIB * SAV - c ++All Articles