Use classes instead of ids to select items. If your input elements have a submit-name
class and a desc
description class, you can do this as follows:
$('.submit-name').bind('blur', function(){ $("~ .desc", this).first().removeClass('input-desc-hover').addClass('input-desc'); }).bind('focus', function(){ $("~ .desc", this).first().removeClass('input-desc').addClass('input-desc-hover'); });
$("~ .desc", this).first()
will select the first native element of the input element ( this
) with the desc
class.
Here's the updated jsFiddle for this: http://jsfiddle.net/miroslav/VL2FH/13/
Edit
The joyful solution with $(this).next()
much better.
source share