0

I'm trying to bind all input fields on a 'form page' to the blur event in jquery. If I put a breakpoint in the each it gets paused so I think the code is being called on page load properly and the loop is working okay. I think the syntax is correct for binding the event as well ? I am not getting the alert when I do anything (leave!) any of the fields in my form though so I think something about this is wrong ? Can anyone point it out to me ?

//for each item in the form (:input "selects all input, textarea, select and button elements.") 
    $(' :input').each(function () {
        $('this').bind('blur', function(){
            alert ("nasty, shoudl be a log!");
            myfunction();
        })
    })
2
  • 1
    $(':input').on('blur', function() { // DO THINGS }); Commented Dec 5, 2019 at 13:21
  • just another comment: using it the way i proposed, will eliminate the need for .each Commented Dec 5, 2019 at 13:37

2 Answers 2

1

You should use:

    $(this).bind('blur', function(){

without the quotes.

Sign up to request clarification or add additional context in comments.

2 Comments

Besides, now it is more common to use $(this).on('blur', function() { ... }.
Thanks I'd switched from on to bind when it didn't work. Missed the real point sadly!
0
$(":input").bind('blur',() => yourfunction());

Just add the event call into your jQuery selector.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.