Get the text of a DOM – João Martins Dec 05 '14 at 12:22

  • 1
    @JoãoMartins oh, ok. I updated my answer. .html() only returns the content of the tag, so you have to use outerHTML – Andy Dec 05 '14 at 12:37
  • 0
    $(".widget-content").each(function(i){
        console.log($(this).prev());//It prints the correct string that I want "<script id="meta..."
        // get div html
        var getthishtml = $(this).html();
        // empty this div html
        $(this).html();
        // move prev script inside div 
        $($(this).prev()).prependTo(widgetsHtml);
        // append div html
        $(this).append(getthishtml );
        // move next script inside div
        $($(this).next()).prependTo(widgetsHtml);   
    });
    

    DEMO you can check inspent elements to get the result

    Mohamed-Yousef
    • 23,946
    • 3
    • 19
    • 28
    0

    If you want just the plain text of the script tag: http://jsfiddle.net/ef93x2aq/

    var script = documenet.getElementById('metamorph-15-start');
    var text = script.innerText;
    document.write(text);