Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2013
What would you like to do?
<ul id="country-selection" class="list-selection">
<li data-content="Deutschland">Germany</li>
<li data-content="Vereinigtes Königreich von Großbritannien und Nordirland">UK</li>
<li data-content="Finnland">Finland</li>
<li data-content="Spanien">Spain</li>
<li data-content="Other">Other</li>
$.fn.asListSelection = function () {
var $el = $(this);
var $first = $el.children().first();
var selections = $el.clickAsObservable().map(function (e) {
return $('data-content');
// refCount connects the BehaviorSubject automatically at subscribe
var subject = selections.publishValue($first.attr('data-content')).refCount();
subject.subscribe(function (val) {
$el.find('[data-content="' + val + '"]').addClass('selected');
return subject;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment