Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery get label from above
    primarykey
    data
    text
    <p>I am writing a function to update an order receipt every time the user updates and then closes a product pop-up overlay. The function searches each input of the form, and then adds the info to the receipt div if its value is greater than <code>0</code>. I am trying to get the <code>.html()</code> of the label element situated above the input field and which describes the current item, and to use this as the description of the item in the receipt. </p> <p>I have tried using without success:</p> <pre><code> - $this.closest('label').html() - $this.prev('label').html() - $this.find('label').html() - this.element.find('label').html() </code></pre> <p>Here is my code. The section I am talking about is the 'label is' part... </p> <pre><code>function updateOrder(){ var items = ''; $('input').each(function(){ var $this = $(this), i_value = $this.attr('value'); if(i_value &gt; 0){ items += $this.attr('id') + ' Quantity: ' + i_value + '&lt;br/&gt;' + 'label is: ' + $this.closest('label').html() + '&lt;br/&gt;'; } }); $('#d_reciept').html(items); </code></pre> <p>}</p> <p>and a sample form item</p> <pre><code>&lt;tr&gt; &lt;td class="td_thumbs"&gt; &lt;div&gt; &lt;a class="fancybox" data-fancybox-group="vinyl-banners" href="img/products/vinyl-corporateblue.jpg"&gt; &lt;img src="img/products/thumbs/vinyl-corporateblue-thumb.png" alt="vinyl c-blue"/&gt;&lt;/a&gt; &lt;label&gt;Corporate Blue&lt;/label&gt; &lt;/div&gt; &lt;/td&gt; &lt;td&gt;6&lt;/td&gt; &lt;td&gt; &lt;input id="vinyl-blue" type="number" max="6" min="0" value="0"/&gt; &lt;/td&gt; &lt;/tr&gt; </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