-2

Suppose the following very simple HTML code:

<div> Hi!</div>

I want to make this div not to show (to disable it, to block it) in case the browser is IE8. How may I do this? Thank you

Dexture
  • 976
  • 1
  • 11
  • 29
Unknown developer
  • 5,414
  • 13
  • 52
  • 100
  • http://stackoverflow.com/questions/5916900/detect-version-of-browser/16938481#16938481 – john-jones Feb 20 '14 at 08:55
  • The answer to this is all over the net buddy – Dumisani Feb 20 '14 at 08:55
  • google IE stylesheet First – Dexture Feb 20 '14 at 08:55
  • If it's a bigger html fragment you should consider not sending it in the first place by doing a server side detection of IE8 ... or pass a client side detection to the server with which to decide whether to send selectable content to different browsers ... and this solution gives you a way to deal with newer version of IE as they don't support conditional statements – Asons Feb 20 '14 at 09:08
  • May I ask why you want to do like this? .. there might be other ways to achieve what you want. – Asons Feb 20 '14 at 09:12

7 Answers7

3

You can use conditional statements for this, in your case something like this..

<![if !(IE 8)]>
<div> Hi!</div>
<![endif]>

that should do it.

Bryan
  • 3,449
  • 1
  • 19
  • 23
  • How this code may work since it is understood as comment? I 've written it, however "Hi!" never appears whatever browser I use. What am I saying wrong? – Unknown developer Feb 20 '14 at 09:22
  • should work in any browser that's not ie 8... http://msdn.microsoft.com/en-us/library/ms537512.ASPX – Bryan Feb 20 '14 at 09:24
  • Please have a look at www.elgrecoweb.gr. I 've added Why it does not work? It is supposed to be placed next to the circle on the top left... – Unknown developer Feb 20 '14 at 09:54
1

Use the below Code

 <!--[if IE 8 ]>    
   <div> Hi! </div> 
 <![endif]-->
sanjeev
  • 4,405
  • 2
  • 19
  • 27
1

First google answer: IE only stylesheet

Michiel D
  • 126
  • 1
  • 10
1

Try conditional statements for IE http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx

Using pure HTML

<!--[if !IE8]-->
<div>Hi!</div>
<!--[endif]-->

If you want to hide it using css then you can create IE specific css

<div class="hideIE"> Hi!</div>
 <!--[if IE 8]>
    <style>
      .hideIE
      {
       display:none;
      }
    </style>
 <![endif]-->

JSFiddle: http://jsfiddle.net/ankur1990/38jxv/

Ankur Aggarwal
  • 2,993
  • 5
  • 30
  • 56
  • How this code may work since it is understood as comment? I 've written it, however "Hi!" never appears whatever browser I use. What am I saying wrong? – Unknown developer Feb 20 '14 at 09:21
  • these are considered to be comments in html but IE has the extra property of understanding them as downlevel-hidden conditional comment if condition we have written is correct. checkout the link http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx – Ankur Aggarwal Feb 20 '14 at 09:29
  • Found a way to do this using pure HTML and CSS also.Check it out – Ankur Aggarwal Feb 20 '14 at 09:39
  • Please have a look at www.elgrecoweb.gr. I 've added Why it does not work? It is supposed to be placed next to the circle on the top left... – Unknown developer Feb 20 '14 at 09:56
  • Have you tried this code:
    Hi!
    – Ankur Aggarwal Feb 20 '14 at 10:00
  • Ok. Then CSS is the solution according to me. Follow the second part (making display:none only for IE). that will work for sure :) – Ankur Aggarwal Feb 20 '14 at 10:13
0

You can try this. Hide div using style

<!--[if IE 8]>    
    <style>
        div { display:none;} 
    </style>
<![endif]-->

OR, If you want to check for < IE 8

<!--[if lt IE 8]>
    <style>
        div { display:none;} 
    </style>
<![endif]-->
Satpal
  • 132,252
  • 13
  • 159
  • 168
0

You can use HTML 5 boiler plate:

<!--[if IE 8]> <html class="ie8"> <![endif]-->

then you can use:

if( $("html").hasClass("ie8") ) { 
    $('div.ie8').hide();
};   

to hide any div with class ie8 if current browser is IE8

Felix
  • 37,892
  • 8
  • 43
  • 55
0
<!--[if IE 8]>
    <style type="text/css">
          .yourdiv {display:none;}
        </style>
<![endif]-->
Prashobh
  • 9,216
  • 15
  • 61
  • 91