jquery – changing values

A simple one today.

It's a simple operation to change the value inside the input box.

 
<input id="element_id" />
jQuery('#element_id').val("New value")

You can also use the .attr() method to perform the same task.

jQuery('#element_id').attr('value', "New value")

If you had a span which contained text you want to change. Use the .html() method. You want to change the html content inside the tags.

<span id="span_id">Text we begin with</span>
jQuery('#span_id').html("New text that we want")
Posted Thursday, July 8th, 2010 under jQuery.

Comments are closed.