I have a jQuery function to return the values of checked checkboxes in a form:
$.fn.selected_values = function() {
return $(this).map( function() { if( $(this).is(':checked') ) { return this.value; } } ).get().join(",");
};
I was wondering if there is a less cumbersome way to say "$this, plus another criteria". In other words, rather than using if( $(this).is('checked'){...}
in a loop, is there some way to say something like $(this):checked
? Then I could do something like:
$.fn.selected_values = function() {
return $(this):checked.map( function() { return this.value; } ).get().join(",");
};
The existing code does work, but it seems that over time such a selector could result much more readable code. Does it exist?