S
S
skyfly20102015-10-28 10:28:51
JavaScript
skyfly2010, 2015-10-28 10:28:51

How to make string from object HTMLdivelement javascript?

Good day. Can you tell me how to make a string out of an object HTMLdivelement so that you can then view its contents?
For example, we have
var MYQLink = jQuery(html).find(".logo")[0];
The result is an HTMLdivelement. I just want to see what's inside it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-10-28
@skyfly2010

var html = '<div><div class="logo"><p>Content</p><p>Further Elaborated</p></div></div>';

var first = $(html).find(".logo")[0].outerHTML;
var second = $(html).find(".logo").prop('outerHTML');
var third = $('<div>').append($(html).find(".logo")).html();
var fourth = $(html).find(".logo").parent().html();

var correct = '<div class="logo"><p>Content</p><p>Further Elaborated</p></div>';

console.log(first);
console.log(second);
console.log(third);
console.log(fourth);

console.log(first === correct && second === first && third === second && fourth === third);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question