Hel...">

Why does this argument in jQuery return href with bindings

I have this for example:

<div id="example">
    <a href="http://www.google.com/#1">Hello</a>
    <a href="http://www.google.com/#4">Hello</a>
</div>

And this two lines of jQuery:

jQuery("a").filter(function() {
    console.log(""+this+"")
});

Return:

 http://www.google.com/#1

 http://www.google.com/#4

But

jQuery("a").filter(function() {
    console.log(this);
});

Returns

<a href="http://www.google.com/#1">Hello</a>​

<a href="http://www.google.com/#4">Hello</a>​

Why line 2 returns the HREF attribute of the anchor IF 'this' argument, adds the line? JQuery docs say that if a filter has a function argument,"this" is the current DOM element

+5
source share
1 answer

""+thisequivalent to this.toString(). It areturns in the element href(yes, this is strange and probably compatible with what has been useful for a long time, but with what it does on all browsers).

toString, , . : , Chrome html ( , ).

+12

All Articles