the following is the examples <span id="test">test text</span> <span id="btnAddAnswer" style="display:none;"></span> $(''btnAddAnswer'').previous(0); -> test now if the first "span" was changed to "li" <li id="test">test text</li> <span id="btnAddAnswer" style="display:none;"></span> $(''btnAddAnswer'').previous(0); -> undefined if it was changed like this: <li id="test"> <p id="testp">test text</p> </li> <span id="btnAddAnswer" style="display:none;"></span> $(''btnAddAnswer'').previous(0); -> testp I want only to get the value:li#test. What should i do? And Why was there such a phenomenon thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
What browser are you using? All your examples work correctly for me in Firefox. It''s also worth noting that your failing examples are all incorrect HTML. There''s never a valid case where a SPAN can be a sibling of an LI because LI can only come directly below UL and OL, and it''s the only thing that can come below it. -Fred On Mon, Jun 9, 2008 at 2:32 AM, LinkChang <herts-9uewiaClKEY@public.gmane.org> wrote:> > the following is the examples > > <span id="test">test text</span> > <span id="btnAddAnswer" style="display:none;"></span> > $(''btnAddAnswer'').previous(0); -> test-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 9, 5:32 pm, LinkChang <he...-9uewiaClKEY@public.gmane.org> wrote:> the following is the examples > > <span id="test">test text</span> > <span id="btnAddAnswer" style="display:none;"></span> > $(''btnAddAnswer'').previous(0); -> testThe previous method works on siblings (ignoring #text nodes), here "test" is the previous sibling of "btnAddAnswer".> now if the first "span" was changed to "li" > > <li id="test">test text</li> > <span id="btnAddAnswer" style="display:none;"></span> > $(''btnAddAnswer'').previous(0); -> undefinedThat is not valid HTML - a span can''t be a sibling of an li element. Browsers will do something with it (maybe put the span inside the li, maybe wrap it in it''s own li, maybe put it outside the ol or ul), but whatever one browser does you can''t depend on all browsers doing the same thing.> if it was changed like this: > > <li id="test"> > <p id="testp">test text</p> > </li> > <span id="btnAddAnswer" style="display:none;"></span> > $(''btnAddAnswer'').previous(0); -> testpMore invalid HTML, see above. As written, the span is a sibling of the li. Your browser seems to have employed error correction to put the span inside the same li as the p element, so the result (in your browser) is: <li id="test"> <p id="testp">test text</p> <span id="btnAddAnswer" style="display:none;"></span> </li>> I want only to get the value:li#test.Then use $(''test'') to reference the element. What do you think its value is or should be?> What should i do?Fix the HTML.> And Why was there such a phenomenonBecause you are writing invalid HTML. Use a validator: <URL: http://validator.w3.org/ > -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---