1

I am trying to apply an inline-block style to an element (a div to be specific). And in order to achieve this in IE you have to use a hack:

$('#element').css(
    {
        'display'  :    'inline-block',    //applies inline-block to matched elements in all browsers except IE due to hasLayout bug
        'zoom'     :    1,                 //set hasLayout to 'true' in IE
        '*display' :    'inline'           //use asterisk to only apply 'inline' style to IE
    }
);

However, the css() function seems to present the style to the browser such that '*display' doesn't register in IE and so therefore doesn't apply the 'inline' style.

Any ideas on why and/or how to work around this ?

0

4 Answers 4

2

I think this should do it then:

if($.browser.msie){
    $('#element').css({'display' : 'inline'});
}
Sign up to request clarification or add additional context in comments.

4 Comments

jQuery documentation specifically suggests using jQuery.support over jQuery.browser because .browser relies on the User-Agent which is a mess.
I saw that, but it isn't really clear as to how to go about getting browser type.
you missed his {'zoom': 1} :-)
@tegeril: Ive seen that noted in the docs to but as tscully mentions - i didnt see a clear cut way to get the browser type and/or version.
1

jQuery is going to filter out "bad" css properties - ie. hacks when using the css function.

However, Youre in jvascript - DO THE DETECTION IN JAVASCRIPT. There is no reason to use a hack because you have all kinds of tools at your disposal to detect not only for IE but the version. Rambo's solution is adequate :-)

Comments

0

As said above, jQuery's not going to let you apply invalid properties. If you need to do it anyway, put them in a CSS class and toggle the class off and on with addClass() and removeClass().

Comments

0

I think you could try css('display', 'inline')

1 Comment

You think? I think this would be better suited as a comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.