I write a function to update the receipt of an order every time the user is updated, and then closes the product popup. The function searches for each input of the form, and then adds information to the receipt of the receipt, if its value is greater than 0 . I am trying to get the .html() of a label element located above the input field that describes the current element and use it as a description of the element in the receipt.
I tried using without success:
- $this.closest('label').html() - $this.prev('label').html() - $this.find('label').html() - this.element.find('label').html()
Here is my code. The section I'm talking about is part of the 'label is' ...
function updateOrder(){ var items = ''; $('input').each(function(){ var $this = $(this), i_value = $this.attr('value'); if(i_value > 0){ items += $this.attr('id') + ' Quantity: ' + i_value + '<br/>' + 'label is: ' + $this.closest('label').html() + '<br/>'; } }); $('#d_reciept').html(items);
}
and sample shape element
<tr> <td class="td_thumbs"> <div> <a class="fancybox" data-fancybox-group="vinyl-banners" href="img/products/vinyl-corporateblue.jpg"> <img src="img/products/thumbs/vinyl-corporateblue-thumb.png" alt="vinyl c-blue"/></a> <label>Corporate Blue</label> </div> </td> <td>6</td> <td> <input id="vinyl-blue" type="number" max="6" min="0" value="0"/> </td> </tr>
source share