jQuery if url hash, click event/activate javascript

前端 未结 3 1464
悲哀的现实
悲哀的现实 2021-01-01 01:11

So from the home page, i have a link that goes to a products listing page. The product page has expand/collapse divs.

I need the appropriate div to expand depending

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 01:49

    You can use the hash property of the Location object, try the following:

    $(document).ready(function(){
       var id = window.location.hash;
       $(id).trigger('click')
    })
    

    As you are using jQuery instead of using javascript: protocol, you can use the jQuery click method:

    $('#healthysnacks').click(function() {
       // do something here
    })
    

提交回复
热议问题