JSFiddle - React, Tailwind, and code Playground
by NickU
HTML
<input type='text' class='random-input' value='1' />
<input type='text' class='random-input' value='2' />
<input type='text' class='random-input' value='3' />
<input type='text' class='random-input' value='4' />
<input type='text' class='random-input' value='5' />
<input type='text' class='single-input' value='single' />
JavaScript
jQuery.fn.extend({
joinVal: function (separator)
{
if (typeof separator === 'undefined')
separator = ",";
var $this = $(this);
if ($this && $this.length > 1)
return $this.map(function () { return $(this).val(); }).get().join(separator);
else
return $this.val();
}
});
alert( $('.random-input').joinVal() );
alert( $('.single-input').joinVal() );
alert( $('.random-input').joinVal(' ') );