1

I have a jQuery function which should read the values from an array to the text field. However, I am having a problem to read the zero position of an array into the text field.

$(function(){
    var values = ['one', 'two', 'three'];
        $('#room').val(values[0].text());  // not sure about this statement
});

This is my html code

<input id="room" />

1 Answer 1

1

text() is for the text into an element

$(function(){
    var values = ['one', 'two', 'three'];
        $('#room').val(values[0]);
});

Exemple use of text()

<div>Hello World</div>
$("div").text() //this will return Hello World
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.