Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Example</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  body {
    font-family: sans-serif;
  }
</style>
</head>
<body>
  <label for="radio1">
    <img style="vertical-align:middle" />
    <input name="radiogroup" checked type="radio" id="radio1" style="display:none;">
</label>
  
<label for="radio2">
    <img style="vertical-align:middle" />
    <input name="radiogroup" type="radio" id="radio2" style="display:none;">
</label>
<script>
</script>
</body>
</html>
 
 $(document).ready(function() {
    var uncheckedImage = "http://www.gravatar.com/avatar/9d848d8392fc5291a0c77f4064b7e67a?s=32&d=identicon&r=PG";
    var checkedImages = {
        'radio1': "http://www.gravatar.com/avatar/12c61ab81d342435c97a6293c594d76d?s=32&d=identicon&r=PG",
        'radio2': "http://www.gravatar.com/avatar/ca3e484c121268e4c8302616b2395eb9?s=32&d=identicon&r=PG"
    };
   
   
    var radios = $('input:radio');
    
    radios.change(function() {
        var checkedLabels = radios.filter(':checked').parent();
        var uncheckedLabels = radios.filter(':not(:checked)').parent();
    
        uncheckedLabels.children('img').attr('src', uncheckedImage);
      
        checkedLabels.each(function() {
            var image = $(this).children('img');
            var name = $(this).attr('for');
          
            if (checkedImages[name] !== undefined) {
                // We have checked image for this radio button, so set it:
                image.attr('src', checkedImages[name]);
            } else {
                // We don't have checked image for this radio button.
                image.attr('src', uncheckedImage);
            }
        });
    });
   
    // Fire the change event programmatically, so the unchecked image src is set:
    radios.change();
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers