JavaScript
Article
By Sam Deering

jQuery Set DOM Element to Top View Z-Index

By Sam Deering
Last chance to win! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

jQuery function to Set any DOM Element to Top View (bring to front) using CSS Z-Index property.

--ADVERTISEMENT--

jQuery.fn.mb_bringToFront= function(zIndexContext){
    var zi=1;
    var els= zIndexContext && zIndexContext!="auto" ? $(zIndexContext): $("*");
    els.not(".alwaysOnTop").each(function() {
      if($(this).css("position")!="static"){
        var cur = parseInt($(this).css('zIndex'));
        zi = cur > zi ? parseInt($(this).css('zIndex')) : zi;
      }
    });
    $(this).not(".alwaysOnTop").css('zIndex',zi+=1);
    return zi;
  };
Login or Create Account to Comment
Login Create Account
Recommended
Sponsors
Get the most important and interesting stories in tech. Straight to your inbox, daily.Is it good?