Remember our documentation is partly community driven. If you feel something
is not explained well or there is an error. Please register on the wiki and
contribute! :)
--
Brandon Aaron


On Tue, Apr 7, 2009 at 9:28 PM, DBJDBJ <[email protected]> wrote:

>
> For a software library as prominent as jQ this is not good enough, I
> am affraid.
> Beside input, there is textarea element, attribute is not called "val"
> but "value",
> etc ...
>
> --DBJ
>
> On Apr 7, 5:27 pm, Chuck Harmston <[email protected]> wrote:
> > It actually is in the documentation:
> > "The result is a string that contains the combined text contents of all
> > matched elements. This method works on both HTML and XML documents.
> Cannot
> > be used on input elements. For input field text use the val attribute."
> >
> > (Fromhttp://docs.jquery.com/Attributes/text)
> >
> > Chuck Harmstonhttp://chuckharmston.com
> > [email protected]
> >
> > On Tue, Apr 7, 2009 at 12:09 PM, DBJDBJ <[email protected]> wrote:
> >
> > > Very good comment Thomas.
> > > Documentation should indeed mention when and why to use .text()
> > > and .val().
> > > In my experience, 99% of jQuery novices do the same mistake.
> > > I suppose they are used to jQuery benign attitude and expect that
> > > jQuery "knows" what to do if one call's .text() on the input element.
> > > Novices subconsciously, expect form jQ to automagically return the
> > > value of the "value" attribute, or some simillar "magic" if element is
> > > input or textarea etc. So the jQ doc has to be clear this is not what
> > > will happen.
> >
> > > And of course, tutorial needs to explain the reasoning of
> > > allowing jQ code like this :
> >
> > > $().text()
> >
> > > --DBJ
> >
> > > On Apr 6, 5:14 pm, Thomas White <[email protected]> wrote:
> > > > 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