Change content of div - jQuery

后端 未结 6 2120
天命终不由人
天命终不由人 2020-11-29 02:22

How is it possible to change the content of this div, when one of the LINKS is clicked?


      
6条回答
  •  情歌与酒
    2020-11-29 02:38

    You can try the same with replacewith()

    $('.click').click(function() {
        // get the contents of the link that was clicked
        var linkText = $(this).text();
    
        // replace the contents of the div with the link text
        $('#content-container').replaceWith(linkText);
    
        // cancel the default action of the link by returning false
        return false;
    });
    

    The .replaceWith() method removes content from the DOM and inserts new content in its place with a single call.

提交回复
热议问题