1

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

Sebastian
  • 1,873
  • 4
  • 25
  • 57

2 Answers2

1
$(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

Vasiliy vvscode Vanchuk
  • 7,007
  • 2
  • 21
  • 44
0
// open collapsed items when clicking on the corresponding link
$(document).on('click', 'a[href^="#"]', function(ev){
    var targetId = $(ev.target).attr('href'),
    $target = $(targetId);

    $target.parents('.collapse').addClass('show');
});

Same as accepted answer but for usage with Bootstrap Collapse elements