Why i always get a value(bu0) of typing in 3 field different(class="bg_units bu0", class="bg_units bu1", class="bg_units bu2") ?
I want if user typing value in field bu0 get dynamic part 2 class="bg_units bu0" of class (.bu0), as for other:
- if typing each value on field bu0 =get class=>
.bu0 - if typing each value on field bu1 =get class=>
.bu1 - if typing each value on field bu2 =get class=>
.bu2
EXAMPLE: http://jsfiddle.net/jJaYT/
$('.eghamat').live('keyup',function () {
var $this = $(this),
$div = $this.closest('div.find_input'),
bu_num = '.' + $div.find('.bg_units').attr('class').split(" ")[1];
alert(bu_num);
});
Your code should do this:
You are going up to the topmost div, which contains everything, searching for
.bg_unitsand always getting the first one. Just call$this.closest('div.bg_units'),