I want to set my max on the input to be the difference between .total and .sold. Why is the max attribute not being set on the .qty input?
$(document).ready(function() {
var total = $(".total").html();
var sold = $(".sold").html();
var available = $(".available").html(total - sold);
$(".qty").attr({
max: available
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
sold<span class="sold">3</span> total
<span class="total">10</span> available
<span class="available"></span>
<input type="range" min="1" value="1" class="qty" name='quantity' oninput="num.value = this.value">
<output id="num">0</output>
attr->max: +total - +sold$(document).ready(function() { var total = $(".total").html(); var sold = $(".sold").html(); $(".qty").attr({ max: +total - +sold }); });works the same way but less code is better always.