Thanks alot Richard
I finally came up with the following (makes a nested list of checkboxes and
their labels behave like a tree):
-Olivier
(function($){
$.fn.treeview = function(o){
var defaults = {
minus:
'url(style/site/interface/public/treeview/minus.gif) 0 0 no-repeat',
plus:
'url(style/site/interface/public/treeview/plus.gif) 0 0 no-repeat'
};
var opt = $.extend(defaults, o);
var $uls = $('ul', this);
var setparentbg = function(o){
if ($(o).css('display') != 'none')
$(o).parent().children('label').css({background: opt.minus});
else
$(o).parent().children('label').css({background: opt.plus});
}
//add plus / minus icons
$uls.each(function(i, o){
setparentbg($(o));
});
//set behavior
$('li', this).each(function(i, o){
if ($('ul', o).length != 0){
$(o).children('label').toggle(
function(){
$(o).children('ul').hide('slow');
$(o).children('label').css({background: opt.plus});
},
function(){
$(o).children('ul').show('slow');
$(o).children('label').css({background: opt.minus});
}
);
}
});
}
})(jQuery);
On Feb 7, 2008 3:50 PM, Richard D. Worth [EMAIL PROTECTED] wrote:
On Feb 7, 2008 6:54 AM, Olivier Percebois-Garve [EMAIL PROTECTED]
wrote:
$li.each(function(o, i){
$(o).setBg();
});
I think you want:
$li.each(function(i, o) {
setBg(o);
});
-or-
$li.each(function() {
setBg(this);
});
Also, on the documentation for each():
http://docs.jquery.com/Core/each
I noticed i comes first, o second.
- Richard