Thanks. Here's what I ended up doing, if anyone's curious. It would be slick if there were some event that gets fired when an element is moved to a different location in the DOM tree so I wouldn't have to keep track of that (there are a few places in my "real" code where that could happen), but this will have to do.

$(function() {
    $('[EMAIL PROTECTED]').click(function() {
        this.wasChecked = this.checked;
    });

    function move(from, to) {
        return function() {
            $(from + ' input').appendTo(to);
            $(to + ' [EMAIL PROTECTED]').each(function() {
                this.checked = this.wasChecked;
            });
        }       
    }

    $('#btn').toggle(move('#d1', '#d2'), move('#d2', '#d1'));
});


On 10/12/06, Klaus Hartl <[EMAIL PROTECTED]> wrote:


Todd Menier schrieb:
> Hello,
> The following test code moves 2 form elements from one location in the
> DOM to another. Both elements retain their state just fine in FireFox,
> but in IE the current state of the checkbox is lost when the element is
> moved:
>
> <script>
> $(function() {
>     $('#btn').toggle(
>         function() {$('#d1 input').appendTo('#d2');},
>         function() {$('#d2 input').appendTo('#d1');}
>     );
> });
> </script>
>
> <button id="btn">move</button>
> <div id="d1">1:<input type="checkbox"/><input type="text"/></div>
> <div id="d2">2:</div>
>
> Is there a "preferred" way to deal with this in jQuery? I can think of a
> number of ways to deal with it, but I would imagine this is a very
> common scenario, so I thought I'd ping the group before proceeding with
> my hack. :-)
>

Not sure, but I think it's nearly impossible to be handled by jQuery
without much overhead, so this should be regarded as an IE bug to work
around...:

$(function() {
     $('#btn').toggle(
         function() {
             var jqInput = $('#d1 input');
             var checked = jqInput[0].checked;
             jqInput.appendTo('#d2')[0].checked = checked;
         },
         function() {
             ...
         }
     );
});


-- Klaus

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to