How to dynamically add a style for text-align using jQuery

前端 未结 11 883
暗喜
暗喜 2020-12-08 04:19

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.

Currently in jQuery yo

11条回答
  •  悲&欢浪女
    2020-12-08 04:36

    Interesting. I got the same problem as you when I wrote a test version.

    The solution is to use jquery's ability to chain and do:

    $(this).width(500).css("text-align", "center");
    

    Interesting find though.

    To expand a bit, the following does not work

    $(this).width(500);
    $(this).css("text-align", "center");
    

    and results only in the width being set on the style. Chaining the two, as I suggested above, does seem to work.

提交回复
热议问题