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")
This entry was posted in jQuery. Bookmark the permalink. Both comments and trackbacks are currently closed.

Page optimized by WP Minify WordPress Plugin