On Jun 9, 5:32 pm, LinkChang <[EMAIL PROTECTED]> wrote:
> the following is the examples
>
>    <span id="test">test text</span>
>    <span id="btnAddAnswer" style="display:none;"></span>
>    $('btnAddAnswer').previous(0); -> test

The 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); -> undefined

That 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); -> testp

More 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 phenomenon

Because 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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to