[jQuery] Re: Plugin development: Defaults & options: Questions?
Hi Scott! Thanks again for the help. I really appreciate it. :)
> Looks right to me. One alternative, which wouldn't break the chain if
> target is not supplied properly, would be this:
Ah, right. That is a smart solution. Thanks for the clarification!
> I don't think it's overkill for your initial jQuery object. I would
> ...<snip>...
> matched element.
Ah, very interesting. Thanks!
I will probably stick with jQuery.each(), but it is nice to see
alternative syntax.
> But this leads to a more fundamental question, of why would this be a
> ...<snip>...
> You could still use jQuery inside the function.
Interesting... That is a great observation! Lol.
You know, I will probably end up using a function now that you point
it out... But this has been a great learning experience.
Here is my actual code (simply splitting a ol/ul into two divs):
==========
$.fn.splitList = function(id) {
var $target = $('#' + id);
if($target.length > 0) {
// Traverse all nodes:
return this.each(function() {
var $this = $(this);
var $clone = $this.clone();
$('li:odd', $this).remove();
$('li:even', $clone).remove();
$target.append($clone);
});
} // $target
};
})(jQuery);
$('#catList').splitList('catFlow');
==========
> Perhaps it's just to learn jQuery plug-ins, and there's nothing wrong
> with that. But if it doesn't work on multiple elements, should it
> really be a plug-in? Food for thought, anyway.
Definitely food for thought. Seems like a simple function would do the
trick.
I would love to figure out how to make it work on more than UL/OL...
For example, I am using the call twice:
$('#catList').splitList('catFlow');
$('#venList').splitList('venFlow');
Might be cool to do something like this:
$('#catList, #venList').splitList({ 'catFlow', 'venFlow' });
But, hehe, that might be overkill and/or just plain silly! :D
Thanks again for the help Scott! I owe you one.
Have an excellent day!
Cheers,
Micky
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home