sblundy sblundy - 1 year ago 77
HTML Question

How do I replace text inside a div element?

I need to set the text within a DIV element dynamically. What is the best, browser safe approach? I have prototypejs and scriptaculous available.

<div id="panel">
<div id="field_name">TEXT GOES HERE</div>

Here's what the function will look like:

function showPanel(fieldName) {
var fieldNameElement = document.getElementById('field_name');
//Make replacement here

Answer Source

I would use Prototype's update method which supports plain text, an HTML snippet or any JavaScript object that defines a toString method.

$("field_name").update("New text");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download