forms - jQuery clear button inside every text input field -
i want use jquery dynamically add clear button (an x) @ right of every input field on site. after having looked @ examples, of these require me change actual input fields can't throughout entire site.
is there simple jquery script can use? script add clear button every input field of type "text". regardless of class.
thanks!
an extreme rough draft.
$('input[type=text]').each(function(){ var $this = $(this); $('<div class="clrinput"/>').css({ position:'absolute', left: $this.offset().left + $this.width() + 10, //10 spacing edge top: $this.offset().top, width: $this.height(), height: $this.height() }).text(' x ').data('inputeq', $this.index()).appendto('body'); }); $(document).on('click', '.clrinput', function(){ $('input[type=text]').eq($(this).data('inputeq')).val(''); });
note
to preserve performance, replace document
closest static parent element.
Comments
Post a Comment