21 Jan 2010

A JQuery function to set the value of all input controls which have an ID containing a given string


function setAll(idFilter, value) {

$('input[id*=' + idFilter + ']').each(function() {
$(this).val(value);
});
}


JQuery has some superduper wildcard attribute selectors like *= (contains), ^= (begins with) and $= (ends with). More here.

No comments:

Post a Comment

Comments are very welcome but are moderated to prevent spam.

If I helped you out today, you can buy me a beer below. Cheers!