$(document).ready(function() {
var parent = $('#foo');
parent.find('#bar').val('hi');
console.log(parent.prop('outerHTML'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="foo">
<input type='text' id="bar" value="" />
</div>
Run codeHide resultI have a container div with a child input element, the initial value is empty, after that I change its value using jQuery and try to get the modified html string using .prop ('outerHTML'). However, it returns:
<div id="foo"><input type="text" id="bar" value=""></div>
I need to return it as:
<div id="foo"><input type="text" id="bar" value="hi"></div>
Is it possible?
source
share