Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy html div in javascript variable using jquery

in my aspx page i have a div which contains simple html ,has some id(say 'datadiv')

using jquery i want to get the html of that div (entire div) into a JavaScript variable

how can it be done?

thank you.

like image 889
dexter Avatar asked Sep 30 '26 00:09

dexter


2 Answers

var someVar = $("#somediv").html();
like image 57
kjagiello Avatar answered Oct 01 '26 15:10

kjagiello


If you want the equivalent of Internet Explorer's outerHTML to retrieve both the div and it's contents then the function from this page that extends JQuery should help:#

jQuery.fn.outerHTML = function() {
    return $('<div>').append( this.eq(0).clone() ).html();
};

Then call:

var html = $('#datadiv').outerHTML();

like image 36
Karl B Avatar answered Oct 01 '26 17:10

Karl B