JQuery -.val () returns the old value

I'm having problems, I use https://github.com/mailcheck/mailcheck

with this function

                $('#email').on('keypress', function(event) {
                $(this).mailcheck({
                    suggested: function(element, suggestion) {
                        $('#email_check').html("Did you mean <b><i><a href='#' id='suggest_email'>" + suggestion.full + "</a></b></i>?");
                        $('#suggest_email').on('click', function(event) {
                            event.preventDefault();
                            $('#email').val($(this).text());
                            $('#email_check').empty();
                            $('.error_js').empty()
                        });
                    },
                    empty: function(element) {
                        $('#email_check').empty();
                        $('.error_js').empty()
                    }
                });
            });

But when the script uses:

opts.email = this.val(); 

(line 263 of this file https://github.com/mailcheck/mailcheck/blob/master/src/mailcheck.js )

this.val () returns the old value of my input. I tried to use

this.attr("value");

and

this.prop("value");

Same problem.

When I do console.log (this); and look for the value of my input, in the object, that's good, it contains a good value.

How to get the correct value? That is why I am turning to you for help.

Thank.

+4
source share
2 answers

keypress, , value character input. keyup

$('#email').on('keyup', function(event) {
                $(this).mailcheck({
                    suggested: function(element, suggestion) {
                        $('#email_check').html("Did you mean <b><i><a href='#' id='suggest_email'>" + suggestion.full + "</a></b></i>?");
                        $('#suggest_email').on('click', function(event) {
                            event.preventDefault();
                            $('#email').val($(this).text());
                            $('#email_check').empty();
                            $('.error_js').empty()
                        });
                    },
                    empty: function(element) {
                        $('#email_check').empty();
                        $('.error_js').empty()
                    }
                });
            });
+8

, , , , , . , .

keyup .

+1

All Articles