Skip to content

Instantly share code, notes, and snippets.

@tobych
Last active December 20, 2015 16:19
Show Gist options
  • Save tobych/6160507 to your computer and use it in GitHub Desktop.
Save tobych/6160507 to your computer and use it in GitHub Desktop.
Applying Bootstrap label class based on custom attribute
<span class="statusLabel" data-status="{{ status.name }}">{{ status.name }}</span>
...
<script type="text/javascript">
$('.statusLabel').addClass(function() {
var classes = {
"Never seen": 'label',
"OK": "label label-success",
"Relocated": "label label-warning",
"Missing": "label label-danger"
}
var status = $(this).attr('data-status');
return classes[status]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment