admin管理员组文章数量:1415673
Is it possible using jQuery to get whole div content(dynamically generated elements) with values? For example, child element may be a div, span, select, or input?
I am trying to save whole div content(generated on fly) with values as .html file. I tried with one div which has form and input elements.
HTML:
<div id="inputs">
<form class="mainForm">
<div style="height: 100%;" id="div1">
<label>Input1</label>
<input type="text" id="input1" name="input1"/>
</div>
</form>
</div>
<input id="addform" type="button" value="Click to add Input"/>
<input id="getform" type="button" value="Click to get html"/>
jQuery:
$(document).ready(function(){
$("input#addform").click(function(){
$("div#inputs").append($('form.mainForm').clone().html());
});
$("input#getform").click(function(){
alert($("div#inputs").clone().html());
});
});
FIDDLE:
/
How to get whole div#inputs
content with values (entered by user) On click of Click to get html
button?
Help would be appreciated.
P.S: Here I used only one input in form. But in my real case, we do have select, span, image, etc.
Is it possible using jQuery to get whole div content(dynamically generated elements) with values? For example, child element may be a div, span, select, or input?
I am trying to save whole div content(generated on fly) with values as .html file. I tried with one div which has form and input elements.
HTML:
<div id="inputs">
<form class="mainForm">
<div style="height: 100%;" id="div1">
<label>Input1</label>
<input type="text" id="input1" name="input1"/>
</div>
</form>
</div>
<input id="addform" type="button" value="Click to add Input"/>
<input id="getform" type="button" value="Click to get html"/>
jQuery:
$(document).ready(function(){
$("input#addform").click(function(){
$("div#inputs").append($('form.mainForm').clone().html());
});
$("input#getform").click(function(){
alert($("div#inputs").clone().html());
});
});
FIDDLE:
http://jsfiddle/UhJfn/
How to get whole div#inputs
content with values (entered by user) On click of Click to get html
button?
Help would be appreciated.
P.S: Here I used only one input in form. But in my real case, we do have select, span, image, etc.
Share Improve this question edited Feb 1, 2015 at 18:28 Deduplicator 45.8k7 gold badges72 silver badges123 bronze badges asked Nov 24, 2013 at 18:17 KiranKiran 20.3k11 gold badges71 silver badges101 bronze badges 5- wouldn't you just need values and types since you already know the html structure? A more real world demo would help – charlietfl Commented Nov 24, 2013 at 18:20
- @charlietfl I just mentioned one div. But we have 10 divs with different html structure. I need to save whole html content as .html file. – Kiran Commented Nov 24, 2013 at 18:23
- seems to me that an array of objects with all the attributes/properties needed to replicate html output would make more sense than relying on browser to modify html and then copy that – charlietfl Commented Nov 24, 2013 at 18:30
- @Oliver Have you checked out my solution.? – Rajaprabhu Aravindasamy Commented Nov 24, 2013 at 18:47
- @RajaprabhuAravindasamy How can we update values for select tag? And select tag options will be dynamic. – Kiran Commented Nov 25, 2013 at 14:36
1 Answer
Reset to default 1Try this,
You have to explicitly update the value
attribute to achieve your need.
$(document).ready(function(){
$(document).on('keyup','input[type="text"]',function(){
$(this).attr('value',$(this).val());
});
$("input#addform").click(function(){
$("div#inputs").append($('form.mainForm').clone().html());
});
$("input#getform").click(function(){
alert($("div#inputs").clone().html());
});
});
DEMO
本文标签: javascriptGet html elements (dynamically generated) with values using jQueryStack Overflow
版权声明:本文标题:javascript - Get html elements (dynamically generated) with values using jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745222816a2648473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论