First off the selector 'a[href*="#"]'
means any link that has a #
in the href
attribute. For example, it would match the following elements:
<a href='#someSection'>Blah</a>
<a href='#otherSection'>Foo</a>
<a href='foobar.html#otherSection'>Foo</a>
See Selectors/attributeContains from the jQuery documentation.
As for location.host
and location.pathname
, they refer to the host and the path in the current url.
For example, if the page was located at http://www.example.com/somepage.html
, then:
location.host
would be www.example.com
location.pathname
would be /somepage.html
As for this.hash
, that is a property on the link that was clicked, which will evaluate to the 'hash' portion of the link. For example:
<a href="somepage.html#someSection">Foobar</a>
For the element above, this.hash
would be #someSection
.
Lastly, as for .size()
, in the case above, that is checking the number of elements that were selected in the jQuery object.
The author of the code you posted is attempting to do something cute: he's expecting that his page will have an element present that has an id
matching the hash
of the link that was clicked.
For example, if this.hash
is #someSection
, the author checks if there is an element with id
equal to 'someSection'"
var target = $('#someSection');
// if target.size() is 0, that means there was no such element with id = 'someSection'