Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Getting the whole div to be clickable

I'm trying to get the whole image grid to be clickable and display the radio button being switched. Not really sure how to get this done, but im sure jquery can do it. If someone could please point to towards the correct direction, thanks

     <form class="glass_selection content">
        <ul class = "options">
          <div class=" image_grid">                
            <div class="image_wrapper">
            <img src="img/hit.gif" alt="Pie" style="height: 174px;" >
            </div>
            <li><input type="radio" name="glass_selection" id="roundedOne" value="pipe" checked="">
            <span></span>  
            <label for="pie">Pie</label> 
            </li>
          </div>             
          <div class="image_grid">
            <div class="image_wrapper">
            <img src="img/hit.gif" alt="Bow" style="height: 174px;">
            </div>
            <li><label for="roundedOne">
            <input type="radio" name="glass_selection" id="roundedOne" value="bow">
            <span></span>  
            Bow</label> 
            </li>  
          </div>
        </ul>
      </form>

1 Answer

From what i can understand, you want to toggle a radio button on/off when a certain div is clicked? If you are able to use jQuery, here is the solution:

$(<div selector>).click(function() {
  $(<radio selector>).prop("checked", !$(<radio selector>).prop("checked"));
});

Obviously replace selectors with appropriate IDs/Classes etc... :)