user3818963
user3818963

Reputation: 53

jQuery change text in button

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.

Upvotes: 0

Views: 74

Answers (4)

Mritunjay
Mritunjay

Reputation: 25882

$('button').text('some text');

Upvotes: 1

Mike Shi
Mike Shi

Reputation: 474

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');

Upvotes: 2

captainsac
captainsac

Reputation: 2490

Use .text method using button selector

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

Upvotes: 2

ssut
ssut

Reputation: 441

$('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$

Upvotes: 1

Related Questions