Replacing radio buttons with background images
-
I’ve cloned the ‘white’ template and am trying to customize a poll. I’d like to remove the radio buttons from each yop-poll-answers ul li, and replace them with background images. That background image should toggle when the li is clicked, to display a different bg after clicking/voting. I’d also like to remove the ‘vote’ button. I’m wondering if any of this will conflict with the YOP logic?
I’ve added the following jQuery within the javascript panel in the Poll editor. I’m not good with jQuery and can’t understand why this function appears to do absolutely nothing.
Any guidance to reach the goals stated above would be welcome.
$(function() { // replace the checkboxes with the images $("input name=['yop_poll_answer']").each(function() { if ($(this).attr('checked')) { // radio button is checked onload $(this).hide(); $(this).after($("<img src='../../themes/mytheme/media/img/poll-item.png' class='radioButtonImage' />")); } else { // radio button is not checked $(this).hide(); $(this).after($("<img src='../../themes/mytheme/media/img/poll-item-checked.png' class='radioButtonImage' />")); } }); // setup click events to change the images $("input.radioButtonImage").click(function() { if($(this).attr('src') == '../../themes/mytheme/media/img/poll-item-checked.png') { // its checked, so uncheck it $(this).attr('src', '../../themes/mytheme/media/img/poll-item.png'); $(this).prev().attr('checked', 'false'); } else { // its not checked, so check it $(this).attr('src', '../../themes/mytheme/media/img/poll-item-checked.png'); $(this).prev().attr('checked', 'true'); } }); });
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Replacing radio buttons with background images’ is closed to new replies.