0

I need to change the text in a button but it's not working. This is what I've come up with thus far:

var newElemen = $(<button text='Text changed..'></button>);                  
document.append$(newElemen);

I've also prepared a jsFiddle example.

2
  • 3
    I'll fix it for only 2 horses (or a camel), but that's my final offer ! Commented Jul 9, 2014 at 5:36
  • Ah, what the heck -> jsfiddle.net/zLf3k/1 Commented Jul 9, 2014 at 5:37

4 Answers 4

2

Don't spend too many horses on this.

You need to first look at how jQuery's selector works. It works similar to CSS selectors (if you're not familiar with that I suggest you start with something more basic).

If you need a quick review on jQuery syntax. In your example you need to use the element selector $('button') and then you'll want to apply the .text() function to change the text for the button. So if you put it together. You'll want to select the button and then apply the text() function, passing in the string you want to change the text to, to change it's text.

$('button').text('Insert Text Here');

Sign up to request clarification or add additional context in comments.

Comments

2

Use .text method using button selector

$("button").text('Text changed..');

Comments

1
$('button').text('new text');

fiddle: http://jsfiddle.net/zLf3k/3/

  1. jQuery selector must be String
  2. created new DOM element when you use html element on jQuery selector
  3. use $(document).append instead of document.append$

Comments

1
$('button').text('some 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.