Skip to content

Instantly share code, notes, and snippets.

@andreas-it-dev
Last active January 2, 2017 12:25
Show Gist options
  • Save andreas-it-dev/ef54077885d7cbc47baa31d18c98f793 to your computer and use it in GitHub Desktop.
Save andreas-it-dev/ef54077885d7cbc47baa31d18c98f793 to your computer and use it in GitHub Desktop.
$.fn.keepInSync = function($targets) {
// join together all the elements you want to keep in sync
var $els = $targets.add(this);
$els.on("keyup change", function() {
var $this = $(this);
// exclude the current element since it already has the value
$els.not($this).val($this.val());
});
return this;
};
var sync = document.getElementsByClassName("sync");
for(var i = 0; i < sync.length; i++)
{
select = ('.' + Array.from(sync.item(i).classList).join('.'));
$(select).keepInSync($(select));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment