JavaScript returns [object Object]

javascript, jquery

Solution

Try:

$(function(){
    var content = $('#info').get(0).outerHTML;
    $('#info').replaceWith('<div id="infobox" class="reveal-modal">'+content+'<a class="close-reveal-modal">&#215;</a></div>');
})

The `$('#info').get(0).outerHTML` returns `<div id="info">anything</div>`. But if just want the content, use `$('#info').html()`, that returns `anything`.

Problem

I'm trying to get this running ``` $('#info').replaceWith('<div id="infobox" class="reveal-modal">'+$('#info').contents()+'<a class="close-reveal-modal">&#215;</a></div>'); ``` but It just gives me [object Object]. As I only replace it with $('#info').contents() things work fine.

Original source