After a little bit of help from @Jahnux73 I figured it out myself. So the only thing I had to do is to add :
data-toggle="collapse" data-target=".navbar-ex1-collapse"
to the specific link that I wanted to toggle the navbar. so the link now looks like following:
<a href="#" id="online-offline" data-toggle="collapse"
data-target=".navbar-ex1-collapse" toggle="offline">
<span class="glyphicon glyphicon-off"></span> Go offline
</a>