You could combine those two and stick them both in the document HEAD,
since they both run on "ready" (see other email for why).
There's no need to for the "filter()" function in this case, the
"each()" function will do fine. Both iterate over the collection of
objects, but "filter" is meant for "filtering", as in removing some
elements.
Hmmm and there's some other small optimisations. For example factoring
the hide/show code into it's own function. Can change
"[EMAIL PROTECTED]'checkbox']" to ":checkbox".
Also "normal" is default for show() and hide().
If I may suggest the following (untested):
$(document).ready(function(){
function visibleCheck() {
var $this = $(this);
var ul = $this.siblings("ul");
if ($this.is(":checked"))
ul.hide();
else
ul.show();
}
$(":checkbox")
.click(visibleCheck)
.each(visibleCheck);
});
Karl Rudd
On 2/21/07, Gorkfu <[EMAIL PROTECTED]> wrote:
>
> Ok I finnally got this to work, lol. I came accross filter and it helps hide
> checked checkboxes on page load. =)
>
> Such as (top one for clicks and bottom for page load):
>
> <script type="text/javascript">
> $(document).ready(function(){
> $("[EMAIL PROTECTED]'checkbox']").click(function(){
> if ($(this).is(":checked")){
> $(this).siblings("ul").hide("normal");
> } else {
> $(this).siblings("ul").show("normal");
> }
> });
> });
>
> </script>
> <script type="text/javascript">
> $(document).ready(function(){
> $("[EMAIL PROTECTED]'checkbox']").filter(function(){
> if ($(this).is(":checked")){
> $(this).siblings("ul").hide("normal");
> } else {
> $(this).siblings("ul").show("normal");
> }
> });
> });
> </script>
>
>
> Gorkfu wrote:
> >
> > I understand the ready function and have looked over the documentation.
> > Maybe I wasn't clear enough in my last post and I'm sorry if that's the
> > case.
> >
> > To explain a little further basically I have a php document i made that
> > will load the checkoxes as checked or not checked according to how the
> > data is saved in mysql. I wanted the script to hide checkboxes that are
> > checked as the page is loading.
> >
> > So basically I want the script to do it's thing while the page is loading,
> > not after it has loaded, but from what I understand that is not possible
> > with javascript, unless I'm missing something.
> >
> >
> >
> > Karl Rudd wrote:
> >>
> >> $(document).ready( function() {
> >> /* Stuff to do when the page has loaded */
> >> });
> >>
> >> You might like to take a quick look over the documentation for jQuery.
> >> A good place to start is:
> >>
> >> http://docs.jquery.com/How_jQuery_Works
> >>
> >> It'll make your jQuery life a lot easier :).
> >>
> >> Karl Rudd
> >>
> >> On 2/21/07, Gorkfu <[EMAIL PROTECTED]> wrote:
> >>>
> >>> Thx for all the help everyone. I tried empty before also, it completely
> >>> removes the <li> and blank append doesn't remove a prior append. I'm
> >>> stuck
> >>> figuring this one out.
> >>>
> >>> Also, another thing I ran across is that I would like the javascript to
> >>> run
> >>> when the page loads, if possible. I checked out the load and bind but
> >>> don't
> >>> seam to work for what I want.
> >>>
> >>>
> >>> Olaf wrote:
> >>> >
> >>> > Gorkfu schrieb:
> >>> >> I tried to set up an append text and remove text to a checkbox that
> >>> is
> >>> >> clicked. I tried the following it works for append perfectly but the
> >>> >> remove
> >>> >> manipulation freezes firefox and explorer.
> >>> >
> >>> > Or so:
> >>> >
> >>> > $(document).ready(function(){
> >>> > $("[EMAIL PROTECTED]'checkbox']").click(function(){
> >>> > if ($(this).is(":checked")){
> >>> > $(this).siblings("ul").hide("normal");
> >>> > $(this).parent("li").append("Complete!");
> >>> > } else {
> >>> > $(this).siblings("ul").show("normal");
> >>> > $(this).parent("li").empty();
> >>> > }
> >>> > });
> >>> > });
> >>> >
> >>> >
> >>> > --
> >>> > Viele Grüße, Olaf
> >>> >
> >>> > -------------------------------
> >>> > [EMAIL PROTECTED]
> >>> > http://olaf-bosch.de
> >>> > www.akitafreund.de
> >>> > -------------------------------
> >>> >
> >>> > _______________________________________________
> >>> > jQuery mailing list
> >>> > [email protected]
> >>> > http://jquery.com/discuss/
> >>> >
> >>> >
> >>>
> >>> --
> >>> View this message in context:
> >>> http://www.nabble.com/Loop-Checkbox-Action-Question-tf3246372.html#a9074931
> >>> Sent from the JQuery mailing list archive at Nabble.com.
> >>>
> >>>
> >>> _______________________________________________
> >>> jQuery mailing list
> >>> [email protected]
> >>> http://jquery.com/discuss/
> >>>
> >> _______________________________________________
> >> jQuery mailing list
> >> [email protected]
> >> http://jquery.com/discuss/
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Loop-Checkbox-Action-Question-tf3246372.html#a9078557
> Sent from the JQuery mailing list archive at Nabble.com.
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/