Search code examples
javascriptjqueryhtmltwitter-bootstrapcollapsable

Link to an element which is inside of a bootstrap collapse element


I have a link outside of a collapse element to an anchor inside of the collapsed content. See my plnkr example.

If I collapse the panelat the bottom the anchor tag is not executed anymore. What I want to implement is the following:

If I click on an anchor which is currently not visible (because it is e.g. in an collapsed area), then I want to extend the containing area and then apply the link.

Any ideas how I could accomplish this?

Thanks a lot


Solution

  • $(function(){
      $(document).on('click', 'a[href^="#"]', function(ev){
        var targetId = $(ev.target).attr('href'),
          $target = $(targetId);
    
          $target.parents('.collapse').addClass('in').css({height: ''});
      });
    })
    

    Like this? http://plnkr.co/edit/R2Fjsz9JnLkWEvFKUaAg?p=preview