views:

19

answers:

2

Not sure why text-align property always return left in jQuery for IE?

<script>
    $(function() {
       alert($('#ctl00').css('text-align'))
    });
</script>

<span style="font-weight: bold; text-align: center;" id="ctl00">
+2  A: 

text-align won't work reliably inside a span, because it's not a block-level element. Test it out inside a div, and I think you'll find the results more predictable.

Peter Anselmo
yes you are right too! but I can't change the span to div for this instance, w/o making other major changes... so going for the js solution of textAlign.
Brandon
+2  A: 

this fixed the problem:

textAlignProp = $(this).css('textAlign');

using textAlign instead of text-align.

Brandon
That sounds really wierd. Works both for me in IE7 and 8. Are you sure you quoted `text-align` correctly in your first approach?
jAndy
yes positive - alert($('#ctl00').css('text-align'))also using latest version of jQuery (1.4.2)
Brandon
so, textAlign returns consistent results for me for both IE and FF. Like what Peter suggested also, trying to get a div css by jQuery will not pose a problem.
Brandon