views:

58

answers:

1

I cannot get the blur() function in the following to work:

$('.newselect').focus(function(){
    $(this).parent().append('<div class="select_container"></div>');
});
$('.newselect').blur(function(){
    $(this).parent().remove('.select_container');
});

However if I use a universal selector $('*') (as below) it works, why is this and how can I fix the problem?

$('.newselect').focus(function(){
    $(this).parent().append('<div class="select_container"></div>');
});
$('.newselect').blur(function(){
    $('*').remove('.select_container');
});
+2  A: 

Try this:

$('.newselect').focus(function(){
    $(this).parent().append('<div class="select_container"></div>');
}).blur(function(){
    $(this).siblings('.select_container').remove();
});
PetersenDidIt
Perfect, thanks!
Phil