user1614862 user1614862 - 6 months ago 18
HTML Question

get the html of element itself using jquery .html()

How to get the html of element itself using Jquery html. In the below code I would like get the input element inside div using JQuery as shwon below

<div id="content">content div</div>
<input type='text' id="scheduledDate" class="datetime" />

$(function() {

console.log($('#scheduledDate').html('dsadasdasd'));
$('#content').html($('#scheduledDate').html());
});


EDIT:

Can I get the $("#scheduledDate") as string which represent the real html code of the input box, because my final requirement is I want to pass it to some other SubView( I am using backboneJS) and eventually use that html code in a dust file.
My original requirement was to get that input field as string so that I can pass it to some other function. I know, if I keep it inside a DIV or some other container, I can get the html by using .html method of JQuery. I dont want use some other for that purpose. I am just trying to get html content of the input box itself using it's id.

Answer

A plain or pure JavaScript method, can do better...

scheduledDate.outerHTML //HTML5

or calling by

document.getElementById("scheduledDate").outerHTML //HTML4.01 -FF.

should do/return the same, e.g.:

>>  '<input id="scheduledDate" type="text" value="" calss="datetime">'

if this, is what you are asking for fiddle

p.s.: what do you mean by "calss" ? :-)

Comments