HTML button to save div content using javascript

前端 未结 4 913
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 05:45

I need to save content of div using pure javascript. I just edited one fiddle but I can\'t make it works :(

jsfiddle

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-03 06:34

    In jsfiddle, you can't run a javascript function inside of html events (like onClick) unless the javascript is contained in tags. (nevermind this)

    Try this:

    HTML

    Hello world

    Hi everybody

    JS

    var download_button = document.getElementById('download');
    download_button.onclick = download;
    
    function download(){
        var content = document.getElementById('content')
        console.log(content);
    }
    

    updated jsfiddle

提交回复
热议问题