How $(this.hash) works in jQuery? I presupposed that this script should work like this - if I click to link with href tickets it will show div with id tickets. But it not works.
var search = $("#switcher").find("a"),
hotels = $("#find").children("div").hide();
search.on('click', function (e) {
$(this.hash).show()
e.preventDefault()
});
this.hash reads the href attribute of this, and gets the part of the URL beginning with #. So if the anchor looks like:
<a href="someURL#foobar">
this.hash will be #foobar. When you then use $(this.hash).show(), it's equivalent to doing $("#foobar").show(), so it will show the element with id="foobar".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With