Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

jQuery addClass not working on dynamic changed input

$
0
0

I have an issue on our checkout, where we are using jQuery to add a class to the input fields, when they aren't empty. The code has worked perfectly for our needs so far. The issue now is, that we are using a small plugin that automatic provides the city name, when the zip code is entered. When this happens, the code does not work and the class is not added to the field, until it is clicked.

I can't seem to find a proper solution for this, so any help is appreciated.

$('.input-text').each(function(){
    changeState($(this));
});
$('.input-text').on('focusout', function(){
    changeState($(this));
});
function changeState($formControl){
        if($formControl.val().length > 0){
        $formControl.addClass('has-value');
    }
    else{
        $formControl.removeClass('has-value');
    }
}

Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>