0

I need some explanations. I'm trying to change the text of a button which is in an array of buttons. $buttons is my array of buttons. My question is simple: why can I change the text of all my buttons in my array, but when I target a button "$buttons[1]" it doesn't work.

$buttons.text("My NEW Text");

works and change the text of all buttons in my $buttons array but when I do

$buttons[1].text("My NEW Text");

it give me the error:

"$buttons[1].text is not a function"

2 Answers 2

1

$buttons[1] (or the jQuery equivalent $buttons.get(1)) accesses the actual DOM node, not the jQuery object. There is no text() method on DOM nodes. You should use jquery.eq to access the jQuery object at a particular index:

$buttons.eq(1)
Sign up to request clarification or add additional context in comments.

Comments

0

The simplest (and cleanest) solution would probably be to attach an ID to that button. That way you can easily change the text using:

$("#ButtonId").text("My New Text")

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.