title: How to dynamically add a style for text-align using jQuery
body: <p>I'm trying to correct the usual IE bugs around CSS 2.1 and need a way to alter an elements style properties to add a custom text-align style.</p>
  
  <p>Currently in jQuery you can do something like</p>
  
  <pre><code>$(this).width() or $(this).height() 
  </code></pre>
  
  <p>but I can't seem to find a good way to alter the text-align with this same approach.</p>
  
  <p>The item already has a class and I set the text-align in that class with no luck. Is it possible to just add a text-align CSS attribute to this element after a class is defined?</p>
  
  <p>I have something like this </p>
  
  <pre><code>$(this).css("text-align", "center"); 
  </code></pre>
  
  <p>just after my width adjustment and after I view this in firebug I see only "width" is the only property set on the style.
  Any help?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Whoa - big response to this question! A bit more detail around the problem at hand:</p>
  
  <p>I'm tweaking the js source for <a href="http://www.trirand.com/blog/" rel="noreferrer">jqGrid</a> A3.5 to do some custom sub grid work and the actual JS I'm tweaking is shown below (sorry for using "this" in my examples above, but I wanted to keep this simple for brevity)</p>
  
  <pre><code>var subGridJson = function(sjxml, sbid) {
      var tbl, trdiv, tddiv, result = "", i, cur, sgmap,
      dummy = document.createElement("table");
      tbl = document.createElement("tbody");
      $(dummy).attr({ cellSpacing: "0", cellPadding: "0", border: "0" });
      trdiv = document.createElement("tr");
      for (i = 0; i &lt; ts.p.subGridModel[0].name.length; i++) {
          tddiv = document.createElement("th");
          tddiv.className = "ui-state-default ui-th-column";
          $(tddiv).html(ts.p.subGridModel[0].name[i]);
          $(tddiv).width(ts.p.subGridModel[0].width[i]);
          trdiv.appendChild(tddiv);
      }
      tbl.appendChild(trdiv);
  }
  </code></pre>
  
  <p>I've tried both of the below (from the answers provided) with no luck.</p>
  
  <pre><code>$(tddiv).width(ts.p.subGridModel[0].width[i]).attr('style', 'text-align: center');
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>$(tddiv).width(ts.p.subGridModel[0].width[i]).css('text-align', 'center');
  </code></pre>
  
  <p>I will continue to work on this issue today and post a final solution for anyone feeling my pain around this strange issue.</p>