I want check between id that get in var span, if empty was between it put css for input but it not work. how can fix it?
var span = '#'+$('.valid').closest('.auto_box').find('span').attr('id');
if ($(span+':empty').length != 0) {
//alert('ok')
(this).closest('.auto_box').find('input').css('background-color','#000');
}
See here my full code: http://jsfiddle.net/Pjqv2/2/
You are using
(this)instead of$('.valid')or whatever you meant with it. Also, you are doing this the wrong way;.find('span')returns the jQuery objects set for that span.You don’t need to get it’s ID and then check on that ID again. More importantly, your code seems the need to run on multiple instances of
.auto_box. For that, you need to iterate on the set found by(".valid").closest(".auto_box"), which you can do with the jQuery.each()(.each() in jQuery docs) like this:Your updated jsfiddle with this script: http://jsfiddle.net/dvir_azulay/Pjqv2/4/