abstracted jquery code to function