jQuery change div content

前端 未结 2 1872
死守一世寂寞
死守一世寂寞 2021-01-16 19:16

I need help changing my code so that it changes div content on click to link id example: I click first link, it prints out 1 and so one. And also it will have an unique link

2条回答
  •  一个人的身影
    2021-01-16 20:01

    window.location.hash normally returns an empty string when there is no hash, and you need to check the anchors href, not hash. It does'nt look like the anchors are inside the .tabs element either ?

    $(function () {
        $(window).on('hashchange', function () {
            var tabContainers = $('.tabs > div'),
                hash = window.location.hash != '' ? window.location.hash : '#first';
    
            tabContainers.hide();
            tabContainers.filter(hash).show();
            $('.tabNavigation li a').removeClass('selected');
            $('a[href="' + hash + '"]', '.tabNavigation').addClass('selected');
        }).trigger('hashchange');
    });
    

    I'm gussing you actually have elements with ID's matching the anchors href inside .tabs, and that is't not empty like in the example?

    DEMONSTRATION

提交回复
热议问题