insert/remove HTML content between div tags

后端 未结 7 1947
渐次进展
渐次进展 2020-12-30 01:22

how can I insert some HTML code between

...
using javascript?

Ex:

7条回答
  •  有刺的猬
    2020-12-30 01:35

    That's really kind of an ambiguous request. There are many ways this can be accomplished.

    document.getElementById('mydiv').innerHTML = 'Something';
    

    That is the simplest. OR;

    var spn = document.createElement('span');
    spn.innerHTML = 'Something';
    spn.className = 'prego';
    document.getElementById('mydiv').appendChild(spn);
    

    Preferred to both of these methods would be to use a Javascript library that creates shortcut methods for the simple things like this, such as mootools. (http://mootools.net)

    With mootools this task would look like:

    new Element('span', {'html': 'Something','class':'prego'}).inject($('mydiv'));
    

提交回复
热议问题