Chuck,

Thank you very much for your detailed explanation.
I was so exited about jQuery last couple of days, that I spent most of my
time using it and very little time was left for reading the documentation
;-).
It could be a good idea to include in the documentation for .text(),  a
reference to .val() function stating the deference as you explained it. That
will help other people not  going into the same confusion as I did.

Regards,
Thomas
2009/4/6 Chuck Harmston <[email protected]>

>
> Hello Thomas!
>
> Welcome to the world of jQuery!
>
> The .text() function is not intended to be used on input elements. It
> is designed to return the text (with HTML removed) of the contents of
> an HTML tag.
>
> For example:
>
> <p><b>Hello</b> world</p>
>
> $('p').text() would return "Hello world"
> $('p').html() would return "<b>Hello</b> world"
>
> Since <input>'s DOM element does store the inputted content in the DOM
> tree, a different method needs to be used to access it. Try using
> $('#inputElement').val():
>
> http://docs.jquery.com/Attributes/val
>
> Additionally, $('#inputElement').attr('value') would achieve the same
> effect.
>
> Chuck Harmston
> http://chuckharmston.com
>
>
> On Mon, Apr 6, 2009 at 4:30 AM, Thomas <[email protected]> wrote:
> >
> > Dear jQuerians,
> >
> > I have learned about jQuery a couple of days and now I am using it all
> > over my code ;-).
> >
> > I have a problem and a solution.
> >
> > Then I use $('#inputElement').text()  to get the value of an input
> > element, I receive an empty string. It turns out it is because:
> > 1)  the text function is extracting the text only from the children
> > nodes.
> > 2) .nodeValue  is used to get the content of the DOM node that in case
> > of INPUT element returns an empty string.
> >
> > The solution I am proposing is to here
> http://paste.pocoo.org/show/111208/
> > It deals with two cases - when there are children elements or not and
> > it checks for bouth .value attribute and .nodeValue  attributes.
> >
> > I hope this will help.
> >
> > Regards,
> > Thomas
> >
> >
> > >
> >
>
> >
>


-- 
Thomas White

Mobile:+44 7711 922 966
Skype: thomaswhite
gTalk: thomas.0007
Linked-In:http://www.linkedin.com/in/thomaswhite0007

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" 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/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to