title: Modifying the style attributes of selected table cells with jQuery?
body: <p>I'm building a pretty basic HTML table creator/editor (based on a designMode iframe) at work, using direct DOM manipulation. It's a pain, obviously due to Internet Explorer.</p>
  
  <p>When in designMode, a table inserted into the editing area iframe is resizable and the contents of the cells can be freely edited. In Firefox, rows and columns can also be added and removed. I'm currently focused on editing border widths, foreground and background colors and other things that require DOM work.</p>
  
  <p>The trouble is the lack of proper DOM Selection/Range functionality in IE6/7. I'm unable to find the containing nodes for several simultaneously selected cells. For a single cell it's doable with parentElement, but for several selected cells, parentElement is the TR node that houses the TD cells. I can't figure out how to extract node references to only those TD cells inside that TR that have been selected, due to lack of anchorNode, focusNode and the various offsets that W3C DOM provides.</p>
  
  <p>I've already got the table creation and the style modification for individual cells as well as groups of selected cells implemented for W3C compliant browsers, but I'm completely stuck with the IE implementation. Could jQuery help me? I've never used it, but it seems intuitive enough that it will take less time to master than it will to figure out how to do this with the IE DOM alone.</p>
  
  <p>There are three basic style modification scenarios that need to work:</p>
  
  <ol>
  <li>A table cell that has not been explicitly selected with Ctrl/Cmd-clicking, but has the text cursor inside it, must have its background color changed. The cell may have formatted text or other parentNode/childNode-relationship complicators in it.</li>
  <li>Several explicitly selected table cells (Ctrl/Cmd-clicked, Shift-selected or just "painted over" with the mouse) must have their background colors changed. This has to work for contiguous rectangular selections as well as for scattered, individual selected cells.</li>
  <li>Table-level modifications (border width, color etc.) for the "selected table" need to be possible. That is, in the case of several tables in the editing area, the modification will take place for one or more tables that either have cursor focus (scenario 1) or have selected cells in them (scenario 2).</li>
  </ol>
  
  <p>In Firefox, I already have the code for all three scenarios working. Now I need a cross-browser solution. Can anybody help me?</p>
  
  <p>(IE's problems with selections and ranges have been discussed here before, but not in the context of jQuery. I found these at a glance: <a href="https://stackoverflow.com/questions/164147/character-offset-in-an-internet-explorer-textrange">164147</a>, <a href="https://stackoverflow.com/questions/218043/issue-with-ie-selection-and-range">218043</a>, <a href="https://stackoverflow.com/questions/235411/is-there-an-internet-explorer-approved-substitute-for-selectionstart-and-select">235411</a>)</p>