Skip to content

Instantly share code, notes, and snippets.

@stugoo
Created April 16, 2013 10:50
Show Gist options
  • Save stugoo/5395023 to your computer and use it in GitHub Desktop.
Save stugoo/5395023 to your computer and use it in GitHub Desktop.
Simple text input > preview
var textPreview = function (el) {
var self = this,
input,
output,
initialise = function() {
input = el.querySelector('input') || el.querySelector('textarea'),
target = el.getAttribute('data-textPreview-output-element'),
output = document.body.querySelector('[data-textPreview-output="' + target + '"]') || null;
input.addEventListener('keyup', function(){
outputText();
});
input.onpaste = outputText();
},
outputText = function(){
var value = input.value;
output.innerHTML = value;
};
initialise();
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment