When choosing a color, the bouquet should change to the desired one. Tried to do so, it seems to work, but not in what. What is the mistake or how can it be done differently? enter image description here

<div id="selmimg"><img src="buket-krasniy.png" /></div> <div class="cc-selector" id="bess"> <input id="red" type="radio" name="color" value="red" data-path="buket-krasniy.png" selected /> <label class="drinkcard-cc red" for="red"></label> <input id="white" type="radio" name="color" value="white" data-path="buket-beliy.png" /> <label class="drinkcard-cc white" for="white"></label> <input id="pink" type="radio" name="color" value="pink" data-path="buket-rozoviy.png" /> <label class="drinkcard-cc pink" for="pink"></label> </div> <script> $(document).ready(function(){ $('#bess').change(function(){ $('#selmimg').find('img:first').attr('src', $('#bess input:selected').attr('data-path')); }); }); </script> 

    1 answer 1

    Error in getting active radio input.

    You doing:

     $('#bess input:selected') 

    Will work:

     $('#bess input:checked')