jQuery object to JavaScript object

Alex picture Alex · Apr 4, 2011 · Viewed 57.6k times · Source

If I have a textarea like var txtarea = $('textarea'), how can I set the value to it using the JavaScript property value, and not the jQuery property val()?

I think I need to convert txtarea to a JavaScript object, but how do I?

Answer

karim79 picture karim79 · Apr 4, 2011

You can use the dereferencing operator, or the .get() method to "Retrieve the DOM elements matched by the jQuery object."

Examples:

txtArea[0].value = "something";

or:

txtArea.get(0).value = "something";