Reputation: 6625
HTML:
<div class="wrapper" style="display:none">
<div class="panel"></div>
</div>
JS CALL
var element = $(".wrapper");
element.toggle().children(":first").custom();
$(".wrapper .panel").custom();
CUSTOM JQUERY METHOD
$.fn.custom = function() {
return this.each(function() {
console.log(" this = ", this);
// do something to each dom element.
});
};
Whats odd here is when I do a console.log in IE its showing the first call to the panel element as a
[object HTMLGenericElement]
but the second call shows it as a [objectHTMLDIVElement]
Why is this and how to have the first call be a [objectHTMLDIVElement]
Upvotes: 0
Views: 101
Reputation: 78971
You should use $(this)
instead of this
inside the each
function.
return this.each(function() {
console.log(" this = ", $(this));
// do something to each dom element.
})
Besides, I checked this with chrome, safari, firefox and everywhere I am receiving the <div>
element
Upvotes: 1
Reputation: 55334
According to this JSFiddle, they are both logged as [object HTMLDivElement].
Tested in IE9 (Version 9.0.8112.16421 64-bit).
Upvotes: 0