Skip to content Skip to sidebar Skip to footer

What In This Jquery Code Is Failing For Ie6 And Ie7?

This piece of jQuery duplicates an item in a form. It works in all browsers except for IE6 and IE7. This is because when it duplicates the form -- it does not increment the name at

Solution 1:

You have to clone using the outerHTML! Yikes!

      var $this = $(this);
      if (!$.browser.msie || parseInt($.browser.version) > 7) {
        $this.attr('id', $this.attr('id').replace(/_(\d+)_/, function($0, $1) {
            return '_' + (+$1 + 1) + '_';
        }));
        $this.attr('name', $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
            return '[' + (+$1 + 1) + ']';
        }));
      } else {
        foob_name = $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
            return '[' + (+$1 + 1) + ']';
        });
        foob_id = $this.attr('id', $this.attr('id').replace(/_(\d+)_/, function($0, $1) {
            return '_' + (+$1 + 1) + '_';
        }));

        $this.attr("outerHTML", "<input type='test' name=" + foob_name + " id=" + foob_id + " />");

      };

Post a Comment for "What In This Jquery Code Is Failing For Ie6 And Ie7?"