I want to copy some DOM nodes by html() method. I use val() to modify the input value, then use html() to copy the input node, but the value of the copied input is old!! When I use attr() to modify the input value, then copy it by html(), it looks like RIGHT!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<p id="con1"><input type="text" value="1"></p>
<p id="con2"></p>
<button onclick="doTest1()">test1</button>
<button onclick="doTest2()">test2</button>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
var doTest1 = function() {
$("#con1 > input").val("2");
$("#con2").html( $("#con1").html() );
};
var doTest2 = function() {
$("#con1 > input").attr("value","2");
$("#con2").html( $("#con1").html() );
};
</script>
</body>
</html>