My goal is there is clone button inside the input section, when i click it clone the whole section including the input value which just inputed via jquery.
<section class='sectionContent'>
<button onClick="clone_section(this)"></button>
<input type="text" name="someinput">
<input type="text" name="someinput">
<input type="text" name="someinput">
<input type="text" name="someinput">
<input type="text" name="someinput">
<input type="text" name="someinput">
<script type="text/javascript">
function clone_section(this) {
console.log($(this).find("input"));
}
</script>
when I console log inside the function it gives me different stuff from i directly console like
console.log('.sectionContent').find('input');
I am trying to do is fetch all the input value out and .clone() the whole section then put all the input value inside the new section.
Does anyone come with some better idea? please advise, thank you very much!
Either use .nextAll("input")
or $(obj).parent().find("input")
Please note that this
, is a reserved word, so use the following:
function clone_section(obj) {
console.log($(obj).nextAll("input"));
}
demo
function clone_section(obj) {
console.log($(obj).nextAll("input"));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class='sectionContent'>
<button onClick="clone_section(this)"></button>
<input type="text" name="someinput">
<input type="text" name="someinput">
<input type="text" name="someinput">
<input type="text" name="someinput">
<input type="text" name="someinput">
<input type="text" name="someinput">
</section>