How does $(this.hash) work?

前端 未结 1 488
清歌不尽
清歌不尽 2021-02-01 19:57

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.

相关标签:
1条回答
  • 2021-02-01 20:24

    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".

    0 讨论(0)
提交回复
热议问题