$(this).attr(“id”) not working

前端 未结 9 749
情书的邮戳
情书的邮戳 2020-12-30 02:55

as the title says, I keep getting \"undefined\" when I try to get the id attribute of an element, basically what I want to do is replace an element with an input box when th

9条回答
  •  一向
    一向 (楼主)
    2020-12-30 03:52

    You could also write your entire function as a jQuery extension, so you could do something along the lines of `$('#element').showHideOther();

    (function($) {
        $.extend($.fn, {
            showHideOther: function() {
                $.each(this, function() {
                    var Id = $(this).attr('id');
                    alert(Id);
    
                    ...
    
                    return this;
                });
            }
        });
    })(jQuery);
    

    Not that it answers your question... Just food for thought.

提交回复
热议问题