Skip to content

Instantly share code, notes, and snippets.

@kirbysayshi
Created May 26, 2010 15:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kirbysayshi/414601 to your computer and use it in GitHub Desktop.
Save kirbysayshi/414601 to your computer and use it in GitHub Desktop.
<ul id="mealSelection" class="open">
<li>
<a href="#" class="selectItem item0">
<img src="" alt="" />
<p>1 in 6 families won't be sitting down to dinner tonight.</p>
</a>
</li>
<li>
<a href="#" class="selectItem item1">
<img src="" alt="" />
<p>Without a healthy breakfast, kids can't succeed at school.</p>
</a>
</li>
<li>
<a href="#" class="selectItem item2">
<img src="" alt="" />
<p>34% of American families have to choose between lunch and medicine.</p>
</a>
</li>
</ul>
<script type="text/javascript">
$.fn.extend({
HSelect: function(options) {
var _defaults = {
};
var _settings = $.extend({}, _defaults, options);
return this.each(function() {
var $list = $(this);
var $items = $list.find('li:has(a.selectItem)');
var selectedIndex = 0;
$(this).delegate('li:has(a.selectItem)', 'click', function(e){
e.preventDefault();
if($list.hasClass('open')){
selectedIndex = $(this).index();
console.log( selectedIndex );
} else {
}
$list.toggleClass('closed open');
});
});
}
});
$("#mealSelection").HSelect();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment