Look at the simple little div
containing a radio-button input
. Then look at the Javascript that grabs the div
and clones it with .clone()
, saving it to variable y
, and then finds the input
elements within it, and then iterates over them in order to modify them -- it's supposed to uncheck the radio button -- but when I print the div
with .html()
, the radio button is still checked! But why? And how do I get .html()
to return the unchecked version?
var y = $('div.foo').clone();
console.log(y.html());
y.find('input').each(function(index, el) {
$(el).prop('checked', false); // turn off the radio button
});
console.log(y.html());
//$('input[name=x_0]').prop('checked', false); // this will do it
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="foo">
<input type="radio" name="x_0" value="email" checked="checked"> email
</div>