Grabbing the filed type jquery

Hey,

I’m trying to write a simple plug in. It’s suppose to alert you what type of field is the input.

This is what I did


(function($){
  $.fn.type = function() {
    return alert(this.type);
  };
})(jQuery);

And then I did


$(document).ready(function () {
  $('#pw').type;
});

This returns undefined. But if I attach an event handler like so:


(function($){
  $.fn.type = function() {
    return this.focus(function () {
      alert(this.type);
    }
  };
})(jQuery);

This returns the correct attribute. If I do something like


return this.ready(function () {
  alert(this.type);
};

It still returns undefined. Any help would be great! :slight_smile: thanks.

Oops wrong forum. Can someone move it please!

nvm i figured it out.