jQuery test if min attribute exists

replace short-circuit boolean evaluation with a test for presence of attribute

by helgatheviking

HTML

<input type="numerical" value="" placeholder="test no min" />
<p>min attribute = <span></span></p>

<input type="numerical" min="" value="" placeholder="test empty min" />
<p>min attribute = <span></span></p>

<input type="numerical" min="0" value="" placeholder="test 0 min" />
<p>min attribute = <span></span></p>

<input type="numerical" min="5" value="" placeholder="test 5 min" />
<p>min attribute = <span></span></p>

JavaScript

$('input').each(function() {

  var $input = $(this);
  
  var min = typeof $input.attr('min') !== 'undefined' && $input.attr('min' ) ? parseInt($input.attr('min'), 10) : 1;

  $(this).next('p').find('span').html(min);

});