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

--~--~---------~--~----~------------~-------~--~----~
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