[0,1,2,3], switch .
HTML
<ul class="size_selector">
<li class="top"><input type="radio" class="radioselect" name="id" id="test1" value="0" /><label for="test1">1</label></li>
<li class="top"><input type="radio" class="radioselect" name="id" id="test2" value="1"/> <label for="test2">2</label></li>
<li class="top"><input type="radio" class="radioselect" name="id" id="test3" value="2"/> <label for="test3">3</label></li>
<li class="top"><input type="radio" class="radioselect" name="id" id="test4" value="3"/> <label for="test4">4</label></li>
</ul>
<a id="shopCart" href="#">
Take me to your leader
</a>
JavaScript
var links = ["http://yahoo.com", "http://bing.com", "http://google.com", "http://stackoverflow.com"]
$("input[type='radio']").change(function(){
$("#shopCart").attr("href", links[$(this).val()]);
});
I used the value to indicate which element of the array I would like to replace.
This is more DRY and less redundant than your code.
source
share