Skip to content

Instantly share code, notes, and snippets.

@yratof
Created August 22, 2014 10:31
Show Gist options
  • Select an option

  • Save yratof/7c13851205244a6ef4fd to your computer and use it in GitHub Desktop.

Select an option

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
<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