jQuery: How to Fix the IE Select Box z-index Bug

Posted by Jetlogs @ 12:01 pm
Category: Web Development, jQuery

Had you ever experienced the IE6 z-index bug where a simple select box will always take priority over any predefined z-indices and always show up on top? Ever annoyed to make a floating dialog only to have a select box underneath popup and ruin the dialog? Well you’re not alone…

Example of the Select Box Bug
I’m in your divs, ruining your z-index

Fortunately, there is a fix for this bug. By using an iframe and expanding it over the select box area, the iframe will take precendence over the select box. However, implementing this iframe hack alone can be quite a bit of a hassle.

Thankfully, there is alread a jQuery plugin that will automatically create the iframe for you. The plugin is simply called bgiframe and using it is quick and easy. Just include the script and attach the bgiframe() method to all of your floating layers. Here is a short and quick example:

<head>
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="jquery.bgiframe.js"></script>
	<script type="text/javascript">
		$(document).ready(function()
		{
			$('#floating_div').bgiframe();
		}
	</script>
</head>
<body>
	<select>
		<option>Test</option>
	</select>
	<div id="floating_div">I'm over this select box</div>
</body>

Now those nasty z-index bugs won’t ever trouble you ever again.

Download:
bgiframe Plugin Page


3 Comments »

3 Comments to “jQuery: How to Fix the IE Select Box z-index Bug”

  1. Nathan Mahon
    1

    Another option i’ve seen are javascript libs that roll through your dom looking for selects, and replace them with “select” workalikes (divs and lists and hiddens maybe)… but without a select tag. No Iframes, no selects.

  2. Bhavesh
    2

    when i am passing id of div bgiframe the ul list is not appearing, but when i am passing the id to its ul list then its working.
    I want to pass the div id so what should i do.

    Example

    Colleges
    Career
    Destinations

  3. Jetlogs
    3
    Author Comment

    I think you need to wrap the ul first.

    so

    <div id="ul_wrapper">
    <ul>......</ul>
    </div id="ul_wrapper">

    then

    $(document).ready(function()
    {
        $('#ul_wrapper').bgiframe();
    }

RSS Comment Feed Comments RSS |trackback TrackBack URI

Leave a comment

  • Archives

  • Donations

  • Social Bookmarks

  • Jetlogs.org
    Some Rights Reserved 2007
    Creative Commons License