-2

I have a HTML file which has href attribute which should change dynamically each time the user clicks. But it is not happening here. I am using accordions using bootstrap here. Please see the below code.

<a class="accordion-toggle" data-toggle="collapse"
data-parent="#accordion" href="#collapseOne" translate>
 <div class="row">
    <label class="control-label col-sm-1">{{week.weekNo}} </label> 
<label class="control-label col-sm-6">{{week.weekStartDate}}
            {{week.weekEndDate}}</label> 
<i  class="indicator glyphicon glyphicon-chevron-up  pull-right"
style="margin-right: 15px"></i>
</div>
</a>

How am I supposed to do that? I have gone through few methods to change href dynamically but nothing worked for me. Please help me.

6
  • Can you share those methods ? Commented Dec 21, 2015 at 4:27
  • stackoverflow.com/questions/10172933/…. This is one of the method. Commented Dec 21, 2015 at 4:28
  • This will work just fine. Can you share your code so that one can make out what is going wrong ? Commented Dec 21, 2015 at 4:29
  • are you getting any errors in the developer tools console when you use your variation of the code (clearly you can't use exactly that code as the class is different for a start) Commented Dec 21, 2015 at 4:30
  • @ Jaromanda X Yes. though I change the class name it is not working. What am I supposed to initialize to href and where exactly should I place this function? Commented Dec 21, 2015 at 4:32

1 Answer 1

0
 <script>
   var new_href="http://somelink.com";
    $(document).ready(function(){
        $("button").click(function(){
            $("#link_id").attr("href", new_href);
        });
    });
    </script>

new_href Here you can store the link everytime you need to set dynamically.

Sign up to request clarification or add additional context in comments.

3 Comments

what should be the link_id here in my case
the id of the anchor or link button where you are setting the href
if you are using class use .classname and if id then use #id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.