My hunch is that your code is running before the html elements have loaded.

Your 'update' to this post is the right direction to go in. Typically one
would use Jquery's cunning ready() event to tell us when the dom has loaded
enough to get going. The ready() method takes a function as a param so that
is probably why your updated code worked.

So your code would look like this:

  $(document).ready(function(){

   // Do everything inside this ready function.

    alert( $("#my li").get(2).text() );

  });

You can use the shorthand syntax to make this slightly simpler:

  $(function(){

    alert( $("#my li").get(2).text() );

  });

The solution you stumbled on is kind of right. Slightly less readable but
you'll soon realise the benefits
Hope this helps!

George


Alexey Grischenko wrote:
> 
> Hi!
> 
> Please  I need some help with .get method
> 
> i have some html like 
> 
> <UL id='my'>
>     <LI> text1 </LI>
>     <LI> text2 </LI>
>     <LI> text3 </LI>
> </UL>
> 
> I need to change "text3"
> but when i try something like 
> 
> alert ( $("#my li").get(2).html() )
> I have a error - why?
> the same thing if i try to get 
> alert ( $("#my li").get(2).text() )  and etc
> 
> it seems like the get(2)  really didn't get a the third A element
> 
> How can i  change my "text3"??
> 
> UPDATE
> 
> As i found - $($("#my li").get(2))  will work
> but......   it seems really unreadable and strange.... is it correct or i
> do something wrong?
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Need-help-with-get%28%29-tf2693047.html#a7513490
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to