-1

I have binded blur on an input. On blur, I want to use $(this) and detect this input. Is there a way to do that?

<input data-john="x" data-doe="false">

$('[data-john=x]:not([data-doe=true])').blur(function() {
    console.log($(this))
})

In this example, $(this) is returning Window, not the blurred element.

Is there a way to get input using $(this)?

senty
  • 12,385
  • 28
  • 130
  • 260
  • It doesn't return window, except if you overwrote `$` function to do so. If it is still jQuery's `$`, then `$(anything)` returns a jQuery object instance. – Kaiido Aug 15 '17 at 04:42

1 Answers1

1

You can use $('input') with blur() event and have this or $(this) in your console.log:

$('input').blur(function() {
  console.log(this);
  console.log($(this).data('john'));
  console.log($(this).data('doe'));
  console.log($(this));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input data-john="x" data-doe="false">
Milan Chheda
  • 8,159
  • 3
  • 20
  • 35