Last active
January 2, 2017 12:25
-
-
Save andreas-it-dev/ef54077885d7cbc47baa31d18c98f793 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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