setting content between div tags using javascript

后端 未结 3 1011
孤独总比滥情好
孤独总比滥情好 2020-12-15 03:37

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:



        
相关标签:
3条回答
  • 2020-12-15 03:56

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

    Use the createElement, createTextNode and appendChild methods.

    0 讨论(0)
  • 2020-12-15 04:01

    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.

    0 讨论(0)
  • 2020-12-15 04:07

    Try the following:

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

    msdn link for detail : innerHTML Property

    0 讨论(0)
提交回复
热议问题