 <p>If you know jQuery, you can use:</p> <pre><code>$('input[type=radio]').click(function() { var $this = $(this); $('.square').css('background', $(this).next().text()); }) </code></pre> <p><strong><a href="http://jsfiddle.net/m8fxw/3/" rel="nofollow">Updated Fiddle</a></strong></p>