Skip to content

Instantly share code, notes, and snippets.

@a-ignatov-parc
Last active December 17, 2015 21:58
Show Gist options
  • Save a-ignatov-parc/5678110 to your computer and use it in GitHub Desktop.
Save a-ignatov-parc/5678110 to your computer and use it in GitHub Desktop.
// Original code
$('.__select-email .textfield')
.removeClass('__required __invalid')
.addClass('__' + error.type)
.find('input[name="email"]')
.after('<label class="error">' + error.text + '</label>');
// Short method
var input = $('.__select-email .textfield')
.removeClass('__required __invalid')
.addClass('__' + error.type)
.find('input[name="email"]'),
$('<label class="error">' + error.text + '</label>')
.insertAfter(input)
.width(input.width());
// Another method
$.fn.setElWidthAndInsertAfter = function(el) {
return $(el)
.width(this.width())
.insertAfter(this);
}
$('.__select-email .textfield')
.removeClass('__required __invalid')
.addClass('__' + error.type)
.find('input[name="email"]')
.setElWidthAndInsertAfter('<label class="error">' + error.text + '</label>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment