javascript - Basic Jquery - If Text exists in a TD then Make a DIV Visible -
i'm trying make div on page appear if word exists later on page? , i'd display if words in list of 10 appear on page? place want them inside of td class "sku nobr" after span class "td-title"
i'm total rookie @ this, got work h1 value code don't know how 4523 now??
thanks!!!!!
<script type="text/javascript"> $(document).ready(function(){ if ($(".sku nobr:contains('4523')").length) { $("#thingtohide").removeattr("style").none(); } }); </script>
<div id="thingtohide" style="display: none;">cool text display</div> <tr class="cart-item-row"> <td class="sku nobr"> <span class="td-title">sku:</span> 4523 </td> </tr>
first, html not valid. you're missing <table></table>
tags.
<div id="thingtohide" style="display: none;">cool text display</div> <table> <tbody> <tr class="cart-item-row"> <td class="sku nobr"> <span class="td-title">sku:</span>4523 </td> </tr> </tbody> </table>
second, selector wrong. replace .sku nobr:contains('4523')
.sku:contains('4523')
$(document).ready(function(){ if ($(".sku:contains('4523')").length) { $("#thingtohide").show(); } });
edit if looking number (which can include commas), have more creative. can use filter method. here's demo.
$(document).ready(function(){ // find td class 'sku' containing numbers var $sku = $("td.sku").filter(function () { // assuming number 4523,8563,9997,7757 // text = $.trim($(this).text()); => sku:4523,8563,9997,7757 // text = text.replace(/sku:|,/g, ''); => 4523856399977757 var text = $.trim($(this).text().replace(/sku:|,/g, '')); // check number return text && !isnan(text); }); // check if there matches if ($sku.length) { $("#thingtohide").show(); } });
Comments
Post a Comment