Created
August 22, 2014 10:31
-
-
Save yratof/7c13851205244a6ef4fd to your computer and use it in GitHub Desktop.
When element is clicked, take .class and .value over to a new div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script type="text/javascript"> | |
| jQuery(document).ready(function($) { | |
| $('tr').each(function() { | |
| var row = this; | |
| function contents(){ | |
| // The label | |
| var thing = $('.label', row).text(); | |
| // The label, trimmed and lowercased for a class | |
| var stripper = thing.trim().toLowerCase(); | |
| var newClass = stripper.replace(/\s+/g, ''); | |
| // The value of the thing. | |
| var what = $(this).text(); | |
| //console.log($('.label', row).text() + ': ' + $(this).text()); | |
| if ($('.picked > .picked-' + newClass).length == 0) { | |
| $('.picked').append('<div class="picked-' + newClass + '"><strong>' + thing + '</strong>: ' + what + '</div>'); | |
| } else { | |
| $('.picked > .picked-' + newClass).html('<strong>' + thing + '</strong>: ' + what); | |
| }; | |
| }; | |
| // When .option is clicked, add the label and value to a div | |
| $('.option', row).click(contents); | |
| }); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment