Skip to content

Instantly share code, notes, and snippets.

@TommyZG
Last active February 6, 2018 01:20
Show Gist options
  • Save TommyZG/8d5ffaf94f4b48a5e48b229ee90e7f71 to your computer and use it in GitHub Desktop.
Save TommyZG/8d5ffaf94f4b48a5e48b229ee90e7f71 to your computer and use it in GitHub Desktop.
// ******************* Scroll to element's position
//get parameters are iteration of all objects selected by .selection
$(".selection").get(0).scrollIntoView();
// ******************* Check if checkbox is checked
$(".checkbox").on("change", function () {
if ($(this).is(":checked")) {
doSomething();
} else {
doSomething();
}
});
// ******************* Check checkbox
$(".checkbox").prop('checked', true);
// ******************* Check radio or checkbox depending on value from backend (user.gender = value - "M")
$('input[name="gender"]').filter('[value=' + user.gender + ']').prop("checked", true);
/**
* Group array by key
* @param {array} xs array to group
* @param {string} key string of key to group by
* @returns {Object}
*/
var groupBy = function (xs, key) {
return xs.reduce(function (rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment