How to replace innerHTML of a div using jQuery?

前端 未结 13 1857
北恋
北恋 2020-11-22 11:57

How could I achieve the following:

document.all.regTitle.innerHTML = \'Hello World\';

Using jQuery where regTitle is my di

13条回答
  •  旧巷少年郎
    2020-11-22 12:30

    There are already answers which give how to change Inner HTML of element.

    But I would suggest, you should use some animation like Fade Out/ Fade In to change HTML which gives good effect of changed HTML rather instantly changing inner HTML.

    Use animation to change Inner HTML

    $('#regTitle').fadeOut(500, function() {
        $(this).html('Hello World!').fadeIn(500);
    });
    

    If you have many functions which need this, then you can call common function which changes inner Html.

    function changeInnerHtml(elementPath, newText){
        $(elementPath).fadeOut(500, function() {
            $(this).html(newText).fadeIn(500);
        });
    }
    

提交回复
热议问题