[jQuery] Re: Breadcumb, error in for-loop
Thanks for helping out Althalos, but BrCu really gives me what I want. You see, for each parents('li') jQuery finds a:first, giving me the array I want. However, I wonder if the format of the array doesn't convert to insert as html..
[jQuery] Re: Breadcumb, error in for-loop
Success!!! var BrCu = here.parents('li').find("a:first"); var BText = ""; for (i=3; i>=0; i--){ if (BrCu[i] != undefined){ BText = BText + ' > ' + '' + BrCu.eq (i).html() + ''; }} $('#breadcumb span.ins').html(BText); Thank you for your help :)
[jQuery] Re: Breadcumb, error in for-loop
Thanks! Now we're getting somewhere. (It's my first time writing a fo-expression) You're right about the comparison. It should be: for (i=3; i>=0; i--) > You're not initializing BText. I think this is valid.. http://www.w3schools.com/JS/js_variables.asp It's now writing to the page :)) However there are still a little to work with. First: It writes "undefined" the first time ?? Second: It writes only the http-part, not tag and inner html I can take hand of the last I think.. but the first??
[jQuery] Re: Breadcumb, error in for-loop
You're not initializing BText. Also, the comparison part of your "for" loop is wrong: should be "i == 0", not "i=0". On Sat, Sep 26, 2009 at 10:36 AM, Geir wrote: > > Ok, saw one mistake, overwriting the text on each for. > > So, tried this: > var BrCu = here.parents('li').find("a:first"); > var BText; > for (i=3; i=0; i--){ > if (BrCU[i] != undefined){ > BText = BText + '> ' + BrCu[i]; > }} > $('#breadcumb span.ins').html(BText); > > But Firebug tells me BText is undefined.. No text written to my page.. -- Turtle, turtle, on the ground, Pink and shiny, turn around.
[jQuery] Re: Breadcumb, error in for-loop
Ok, saw one mistake, overwriting the text on each for. So, tried this: var BrCu = here.parents('li').find("a:first"); var BText; for (i=3; i=0; i--){ if (BrCU[i] != undefined){ BText = BText + '> ' + BrCu[i]; }} $('#breadcumb span.ins').html(BText); But Firebug tells me BText is undefined.. No text written to my page..
[jQuery] Re: Breadcumb, error in for-loop
I'm not an expert either, so I may be wrong. But I doubt that BrCU really gives you what you want. find("a:first") will give you ONE element by definition... it will not return an array of elements. I think. Probably you need to do something like this: var el = ""; var BrCu = here.parents('li'); BrCu.each(function () { el = $(this).find("a:first"); bc += ">"+el; }); This will probably not work straight off... but now bc will hold all of the a elements... On 26 Sep, 11:44, Geir wrote: > Hi! > I'm not an expert in js, maybe you can help me with this one: > > var BrCu = here.parents('li').find("a:first"); > for (i=3; i=0; i--){ > if (BrCU[i] != undefined){ > $('#breadcumb span.ins').html('>' + BrCu[i]); > } > }; > > BrCu gives me what I want. But the for-loop is not writing anything to > the page. > Have I misunderstood something? > > var here is current location in a navigation-menu (ul li a ul li a ..) > > Thanks!
[jQuery] Re: Breadcumb, error in for-loop
Ok, understand the "undefined"-writing..