jquery - Remove a td cell containing specific text from being counted -
var donotcounts = 'td.player:contains(s)'; $(data).find('td.two_column_layout .report').each(function (index, element) { if ($(this).find("td.player:not("+donotcounts+")").length !== +requiredstarters && $(this).attr("id") !== "invalidlineup")
i trying count td.player cells , except children span class contain specific letter. here have. set var "donotcounts" , have 2 questions.
how can make var use true or false declaration can decide whether want count or not count , based on true or false setting ?
how can add 2nd var called donotcountp , can remove span warning text p , not counted well, true/false can turn both on or 1 or other ?
example html
<table> <caption><span><a></span></caption> <tbody> <tr><th class="player">text</th><th>text</th></tr> <tr><td class="player"><a>text</a></td><td>text</td></tr> <tr><td class="player"><a>text</a></td><td>text</td></tr> <tr><td class="player"><a>text</a></td><td>text</td></tr> <tr><td class="player"><a>text</a>(<span class="warning">p</span>)</td><td>text</td></tr> <tr><td class="player"><a>do not count td cell having span warning "s" text</a>(<span class="warning">s</span>)</td><td>text</td></tr> </tbody> </table>
if want skip counting td
element contains specific text here can do.
the above fiddle uses below function,
$(document).ready(function () { var count = 0; $("td").each(function () { var tdtext = $(this).children("span.warning").text(); if(tdtext != "s"){ count++; } }); alert(count); });
update 1: understand generating table dynamically , once generated want count td
not contain specific text. if want can use above function after table generated follows,
$.get('http://%host%/%year%/options?l=%leagueid%&o=06', function (data) { $(data).find('td.two_column_layout .report').each(function (index, element) { if ($(this).find("td.player").length !== +requiredstarters && $(this).attr("id") !== "invalidlineup") { var target = $("#invalidlineup").find("tbody"); $(this).find("span a").each(function () { var classname = this.classname; if (clazz[classname]) { return } clazz[classname] = true; target.append("<tr class='oddtablerow'><td>" + $(this)[0].outerhtml + "</td><td class='lineupalert'><a class='lineuplink' href='http://%host%/%year%/options?league_id=%leagueid%&o=02&%franchiseid%'>submit valid lineup</a></td></tr>"); }); } }); //insert function count specific td here var count = 0; $("td").each(function () { var tdtext = $(this).children("span.warning").text(); if(tdtext != "s"){ count++; } }); alert(count); });
update 2:
($(this).find("td.player:not(donotcountout)").length
donotcountout variable guess should written as,
($(this).find("td.player:not("+donotcountout+")").length
update 3: can use multiple :not()
, create variable named donotcountp
, use follows,
var donotcounts = 'td.player:contains(s)'; var donotcountp = 'td.player:contains(p)'; $(data).find('td.two_column_layout .report').each(function (index, element) { if ($(this).find("td.player:not("+donotcounts+"):not("+donotcounts+")").length !== +requiredstarters && $(this).attr("id") !== "invalidlineup")
Comments
Post a Comment