Skip to content Skip to sidebar Skip to footer

Setting Content Between Div Tags Using Javascript

I'm trying to set some content in between some div tags on a JSP page using javascript. currently the div tag on the JSP page looks like this:

Solution 1:

Try the following:

document.getElementById("successAndErrorMessages").innerHTML="someContent"; 

msdn link for detail : innerHTML Property


Solution 2:

See Creating and modifying HTML at what used to be called the Web Standards Curriculum.

Use the createElement, createTextNode and appendChild methods.


Solution 3:

If the number of your messages is limited then the following may help. I used jQuery for the following example, but it works with plain js too.

The innerHtml property did not work for me. So I experimented with ...

    <div id=successAndErrorMessages-1>100% OK</div>
    <div id=successAndErrorMessages-2>This is an error mssg!</div>

and toggled one of the two on/off ...

 $("#successAndErrorMessages-1").css('display', 'none')
 $("#successAndErrorMessages-2").css('display', '')

For some reason I had to fiddle around with the ordering before it worked in all types of browsers.


Post a Comment for "Setting Content Between Div Tags Using Javascript"