开发者

replacing the superfluous 'innerHTML' with something else. Javascript

im looking for a replacement for .innerHTML.. something that can also clear the div and replace it with a string of code i have.. the problem with innerhtml is that it forces me to use superfluous code (anyone know why?) // AND i can't seem to break '<br> more than once in a line..

ive trie开发者_StackOverflow社区d search for an answer but cant find any. any help is appreciated.


What do you mean by superfluous, it is pretty straightforward. Check it out http://jsfiddle.net/s8ajC/.

<div id="test">some content</div>

<script>
document.getElementById('test').innerHTML = 'some<br />content<br />and more';
</script>


use jQuery.

  $('#myDiv').replaceWith(whatever);

that will replace the entirety of that DOM element with whatever you put in it's place..

$('#myDiv').html(whatever);

that will retain the DOM element while replacing all of the contents of the div in the same way innerHTML does.

$('#myDiv').append(whatever);

that will retain the DOM element AND it's content and add your content onto the BACK of that element.

$('#myDiv').prepend(whatever);

that will retain the DOM element AND it's content and add your content onto the FRONT of that element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜