changing href attribute of a link with an input radio button

changing href attribute of a link with an input radio button

Hi guys,

I'm trying to change a href value of a button, but it's not working. I'm using jquery-1.8.0 and created a function like this:

  1. $('input[name=radio-group-1]:radio').change(function() {
  2.       if ($(this).val() == 'no') { 
  3.             $('.btn[href=http://www.google.com]').attr("href","http://www.yahoo.com");
  4.       }
  5. });

HTML:
  1. <label for="yes">Yes</label>
  2. <input type="radio" name="radio-group-1" value="yes" />

  3. <label for="no">No</label>
  4. <input type="radio" name="radio-group-1" value="no" />

  5. <a href="http://www.google.com" class="btn">next</a>

I've made a pen of it here:
http://codepen.io/gentleone/full/gKrAB

Hope someone can point me in the right direction. Thanks in advance!
    • Topic Participants

    • ralph