Note that there are some explanatory texts on larger screens.

plurals
  1. POhide / show div if less or greater than a certain number using jQuery
    primarykey
    data
    text
    <p>I'm trying to us jQuery to hide or show something if less than or greater than 20000</p> <p>This is the table element I'm using. The td.weight is populated dynamically using a custom shipping calculator. There's a max weight returned by the api of 20000 lbs and then it zero's out.</p> <p>I'm attempting to notify the user by hiding or showing a div if their calculated weight is over 20000 lbs or less than 20000 lbs</p> <p>Show div.shipping-weight if this output:</p> <pre><code>&lt;td class="weight"&gt; 20000 &lt;small&gt;&lt;em&gt; lb's &lt;/em&gt;&lt;/small&gt;&lt;br&gt; &lt;div class="shipping-weight"&gt;&lt;small&gt;*Note: Up to 20,000 lbs max. For shipping requirements over 20,000 lb's call our&lt;/small&gt;&lt;br&gt; &lt;small&gt;PRICING HOTLINE: 1-877-444-444 &lt;/small&gt; &lt;/div&gt; &lt;/td&gt; </code></pre> <p>Hide div.shipping-weight if this output:</p> <pre><code>&lt;td class="weight"&gt; 19456 &lt;small&gt;&lt;em&gt; lb's &lt;/em&gt;&lt;/small&gt;&lt;br&gt; &lt;div class="shipping-weight"&gt;&lt;small&gt;*Note: Up to 20,000 lbs max. For shipping requirements over 20,000 lb's call our&lt;/small&gt;&lt;br&gt; &lt;small&gt;PRICING HOTLINE: 1-877-444-444 &lt;/small&gt; &lt;/div&gt; &lt;/td&gt; </code></pre> <p>Here is what I have so far.</p> <pre><code> $('td.weight').filter(function(index){ return parseInt(this.innerHTML) &gt; 20000; }).show('.shipping-weight'); </code></pre> <p>Here's a <a href="http://jsfiddle.net/fNsNj/1/" rel="nofollow">jsfiddel</a></p> <p>*Revision:</p> <p>This doesn't seem to fire in my ajax request but works on jsfiddle. I'm using keyup and livequery to make the request. As follows:</p> <pre><code> $('.input-mini').keyup().livequery('change', function () { url = $(this.form).attr('action'); data = $(this.form).serialize(); $.post(url, data, function () { $('#checkout').load('/store/checkout_table'); $('#checkout_form').attr('action', url); $('.weight').filter(function(index){ var num = parseInt(this.firstChild.textContent); return num &gt;= 20000; }).find('.shipping-weight').show(); $.cookie('all_cookie', null); }); return false; }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload