IE and replaceWith don't save switch state

I'm having a problem replacing not maintaining the state of the moved input of a radio button. I have prepared a simple example to illustrate this problem. This works in FF and Chrome, but not IE.

Is there a way to get around this?

Thanks!

jsbin: http://jsbin.com/unola4/2

the code:

<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<title>IE replaceWith issue</title>
<script type='text/javascript'>
$(function(){
  $('a').click(function(e) {
    e.preventDefault();
    $('#temp').replaceWith($('#window').children());
  });
});
</script>
</head>
<body>
  <a href='#'>run replaceWith</a>
  <p>Select a radio button and then click "run replaceWith". The value persists in FF, but not IE.</p>
  <div id='window' style='background-color: #DDD; height: 100px;'>
    <input id="id_received_date-days_0" type="radio" name="received_date-days" value="30" />
    <input id="id_received_date-days_1" type="radio" name="received_date-days" value="50" />
    <input type='text' name='test-test' />
  </div>
  <br />
  <form id='foo' style='background-color: #EEE'>
    <div id='temp'></div>
  </form>
</body>
</html>

      

+2


a source to share


1 answer


Take the IDs of the checked ones, then check them after replacing:

$('a').click(function(e) {
    e.preventDefault();
    var checkedOnes = $("#window input:checkbox:checked").map(function() {
        return this.id;
    }).get();
    $('#temp').replaceWith($('#window').children());
    $.each(checkedOnes, function(index, value) {
        $("#" + value).attr("checked", "checked"); 
    });
});

      



Also, you get duplicate IDs when you copy these items. I assume you delete the old ones after replacing? Can duplicate identifiers be the cause of the problem?

0


a source







All Articles