I’d like to make a beautiful multiple choice HTML page. I want to have 3 or 4 <div>s including images and/or text, and users should be able to toggle each <div> “on” or “off” by simply clicking anywhere on the <div> (there should be a highlighting effect, if possible with an animation). When the form gets submitted, the server should be sent the state of each <div>, as if it were a checkbox.
I have searched all over the place but could not find something like that. It seems so basic that I probably overlooked something trivial. Any ideas? I already use jQuery and bootstrap, so if there’s a simple solution based only on these frameworks, I’d be very happy.
Thanks.
Edit: I don’t want the <div>s to move or disappear. I just want a “highlighting” effect, such as changing the background color to blue when the <div> is selected, and back to white when it is unselected.
I would recommend starting with a good HTML base. I would probably use a hidden radio button inside each
divand check or uncheck it when thedivwas clicked. The radio button would be a valid item on the form which would submit the selected value.HTML:
JavaScript:
Demo: jsfiddle
Alternative: if you want multiple selected at once
So with radio buttons only one within the radio button group is active at a time. If that is not the behavior you want, you could use a hidden checkbox and toggle it on and off.
HTML:
JavaScript:
Demo: jsfiddle