Reputation: 53
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
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
Reputation: 2490
Use .text method using button selector
$("button").text('Text changed..');
Upvotes: 2
Reputation: 441
$('button').text('new text');
fiddle: http://jsfiddle.net/zLf3k/3/
$(document).append
instead of document.append$
Upvotes: 1