title: Is there a workaround for IE 6/7 "Unspecified Error" bug when accessing offsetParent
body: <p>I'm using jQuery UI's draggable and droppable libraries in a simple ASP.NET proof of concept application. This page uses the ASP.NET AJAX UpdatePanel to do partial page updates. The page allows a user to drop an item into a trashcan div, which will invoke a postback that deletes a record from the database, then rebinds the list (and other controls) that the item was drug from. All of these elements (the draggable items and the trashcan div) are inside an ASP.NET UpdatePanel.</p>
  
  <p>Here is the dragging and dropping initialization script:</p>
  
  <pre><code>    function initDragging()
      {
          $(".person").draggable({helper:'clone'});
          $("#trashcan").droppable({
              accept: '.person',
              tolerance: 'pointer',
              hoverClass: 'trashcan-hover',
              activeClass: 'trashcan-active',
              drop: onTrashCanned
          });
      }
  
      $(document).ready(function(){
          initDragging();
  
          var prm = Sys.WebForms.PageRequestManager.getInstance();
          prm.add_endRequest(function()
          {
              initDragging();
          });
      });
  
      function onTrashCanned(e,ui)
      {
          var id = $('input[id$=hidID]', ui.draggable).val();
          if (id != undefined)
          {
              $('#hidTrashcanID').val(id);
              __doPostBack('btnTrashcan','');
          }
  
      }
  </code></pre>
  
  <p>When the page posts back, partially updating the UpdatePanel's content, I rebind the draggables and droppables. When I then grab a draggable with my cursor, I get an "htmlfile: Unspecified error." exception.  I can resolve this problem in the jQuery library by replacing <code>elem.offsetParent</code> with calls to this function that I wrote:</p>
  
  <pre><code>function IESafeOffsetParent(elem)
  {
      try
      {
          return elem.offsetParent;
      }
      catch(e)
      {        
          return document.body;
      }
  }
  </code></pre>
  
  <p>I also have to avoid calls to elem.getBoundingClientRect() as it throws the same error. For those interested, I only had to make these changes in the <code>jQuery.fn.offset</code> function in the <a href="http://plugins.jquery.com/project/dimensions" rel="nofollow noreferrer">Dimensions Plugin</a>.</p>
  
  <p>My questions are: </p>
  
  <ul>
  <li>Although this works, are there better ways (cleaner; better performance; without having to modify the jQuery library) to  solve this problem?</li>
  <li>If not, what's the best way to manage keeping my changes in sync when I update the jQuery libraries in the future? For, example can I extend the library somewhere other than just inline in the files that I download from the jQuery website.</li>
  </ul>
  
  <p><b>Update:</b></p>
  
  <p>@some It's not publicly accessible, but I will see if SO will let me post the relevant code into this answer. Just create an ASP.NET Web Application (name it <b>DragAndDrop</b>) and create these files. Don't forget to set Complex.aspx as your start page. You'll also need to download the <a href="http://ui.jquery.com/download_builder/" rel="nofollow noreferrer">jQuery UI drag and drop plug in</a> as well as <a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.6.js" rel="nofollow noreferrer">jQuery core</a></p>
  
  <p><b>Complex.aspx</b></p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Complex.aspx.cs" Inherits="DragAndDrop.Complex" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Untitled Page&lt;/title&gt;
      &lt;script src="jquery-1.2.6.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="jquery-ui-personalized-1.5.3.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          function initDragging()
          {
              $(".person").draggable({helper:'clone'});
              $("#trashcan").droppable({
                  accept: '.person',
                  tolerance: 'pointer',
                  hoverClass: 'trashcan-hover',
                  activeClass: 'trashcan-active',
                  drop: onTrashCanned
              });
          }
  
          $(document).ready(function(){
              initDragging();
  
              var prm = Sys.WebForms.PageRequestManager.getInstance();
              prm.add_endRequest(function()
              {
                  initDragging();
              });
          });
  
          function onTrashCanned(e,ui)
          {
              var id = $('input[id$=hidID]', ui.draggable).val();
              if (id != undefined)
              {
                  $('#hidTrashcanID').val(id);
                  __doPostBack('btnTrashcan','');
              }
  
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
      &lt;/asp:ScriptManager&gt;
      &lt;div&gt;
          &lt;asp:UpdatePanel ID="updContent" runat="server" UpdateMode="Always"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:LinkButton ID="btnTrashcan" Text="trashcan" runat="server" CommandName="trashcan" 
              onclick="btnTrashcan_Click" style="display:none;"&gt;&lt;/asp:LinkButton&gt;
          &lt;input type="hidden" id="hidTrashcanID" runat="server" /&gt;
          &lt;asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" /&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td style="width: 300px;"&gt;
                      &lt;asp:DataList ID="lstAllPeople" runat="server" DataSourceID="odsAllPeople"
                          DataKeyField="ID"&gt;
                          &lt;ItemTemplate&gt;
                              &lt;div class="person"&gt;
                                  &lt;asp:HiddenField ID="hidID" runat="server" Value='&lt;%# Eval("ID") %&gt;' /&gt;
                                  Name:
                                  &lt;asp:Label ID="lblName" runat="server" Text='&lt;%# Eval("Name") %&gt;' /&gt;
                                  &lt;br /&gt;
                                  &lt;br /&gt;
                              &lt;/div&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:DataList&gt;
                      &lt;asp:ObjectDataSource ID="odsAllPeople" runat="server" SelectMethod="SelectAllPeople" 
                          TypeName="DragAndDrop.Complex+DataAccess" 
                          onselecting="odsAllPeople_Selecting"&gt;
                          &lt;SelectParameters&gt;
                              &lt;asp:Parameter Name="filter" Type="Object" /&gt;
                          &lt;/SelectParameters&gt;
                      &lt;/asp:ObjectDataSource&gt;
                  &lt;/td&gt;
                  &lt;td style="width: 300px;vertical-align:top;"&gt;
                      &lt;div id="trashcan"&gt;
                          drop here to delete
                      &lt;/div&gt;
                      &lt;asp:DataList ID="lstPeopleToDelete" runat="server" 
                          DataSourceID="odsPeopleToDelete"&gt;
                          &lt;ItemTemplate&gt;
                              ID:
                              &lt;asp:Label ID="IDLabel" runat="server" Text='&lt;%# Eval("ID") %&gt;' /&gt;
                              &lt;br /&gt;
                              Name:
                              &lt;asp:Label ID="NameLabel" runat="server" Text='&lt;%# Eval("Name") %&gt;' /&gt;
                              &lt;br /&gt;
                              &lt;br /&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:DataList&gt;
                      &lt;asp:ObjectDataSource ID="odsPeopleToDelete" runat="server" 
                          onselecting="odsPeopleToDelete_Selecting" SelectMethod="GetDeleteList" 
                          TypeName="DragAndDrop.Complex+DataAccess"&gt;
                          &lt;SelectParameters&gt;
                              &lt;asp:Parameter Name="list" Type="Object" /&gt;
                          &lt;/SelectParameters&gt;
                      &lt;/asp:ObjectDataSource&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;    
      &lt;/ContentTemplate&gt;
      &lt;/asp:UpdatePanel&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><b>Complex.aspx.cs</b></p>
  
  <pre><code>namespace DragAndDrop
  {
      public partial class Complex : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
          }
  
          protected List&lt;int&gt; DeleteList
          {
              get
              {
                  if (ViewState["dl"] == null)
                  {
                      List&lt;int&gt; dl = new List&lt;int&gt;();
                      ViewState["dl"] = dl;
  
                      return dl;
                  }
                  else
                  {
                      return (List&lt;int&gt;)ViewState["dl"];
                  }
              }
          }
  
          public class DataAccess
          {
              public IEnumerable&lt;Person&gt; SelectAllPeople(IEnumerable&lt;int&gt; filter)
              {
                  return Database.SelectAll().Where(p =&gt; !filter.Contains(p.ID));
              }
  
              public IEnumerable&lt;Person&gt; GetDeleteList(IEnumerable&lt;int&gt; list)
              {
                  return Database.SelectAll().Where(p =&gt; list.Contains(p.ID));
              }
          }
  
          protected void odsAllPeople_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
          {
              e.InputParameters["filter"] = this.DeleteList;
          }
  
          protected void odsPeopleToDelete_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
          {
              e.InputParameters["list"] = this.DeleteList;
          }
  
          protected void Button1_Click(object sender, EventArgs e)
          {
              foreach (int id in DeleteList)
              {
                  Database.DeletePerson(id);
              }
  
              DeleteList.Clear();
              lstAllPeople.DataBind();
              lstPeopleToDelete.DataBind();
          }
  
          protected void btnTrashcan_Click(object sender, EventArgs e)
          {
              int id = int.Parse(hidTrashcanID.Value);
              DeleteList.Add(id);
              lstAllPeople.DataBind();
              lstPeopleToDelete.DataBind();
          }
      }
  }
  </code></pre>
  
  <p><b>Database.cs</b></p>
  
  <pre><code>namespace DragAndDrop
  {
      public static class Database
      {
          private static Dictionary&lt;int, Person&gt; _people = new Dictionary&lt;int,Person&gt;();
          static Database()
          {
              Person[] people = new Person[]
              {
                  new Person("Chad")
                  , new Person("Carrie")
                  , new Person("Richard")
                  , new Person("Ron")
              };
              foreach (Person p in people)
              {
                  _people.Add(p.ID, p);
              }
          }
  
          public static IEnumerable&lt;Person&gt; SelectAll()
          {
              return _people.Values;
          }
  
          public static void DeletePerson(int id)
          {
              if (_people.ContainsKey(id))
              {
                  _people.Remove(id);
              }
          }
  
          public static Person CreatePerson(string name)
          {
              Person p = new Person(name);
              _people.Add(p.ID, p);
  
              return p;
          }
      }
  
      public class Person
      {
          private static int _curID = 1;
          public int ID { get; set; }
          public string Name { get; set; }
          public Person()
          {
              ID = _curID++;
          }
  
          public Person(string name)
              : this()
          {
              Name = name;
          }
      }
  }
  </code></pre>