refactor jquery to dynamically add span