Change the opacity of all elements except one div

I am trying to tag all elements on a webpage except one div. I was able to output all the elements with the following jQuery:

$('*').css('opacity', .3);

However, opacity seems to be a property that inherits from the parent elements, even if I explicitly set the opacity of the div to 1. Now I am drawing a space regarding any decisions, so can I help here?

+5
source share
5 answers

, div , , , /. div z-, div . "" div .

+11

, div, ... , jQuery Tools Expose.

, , . script , - div. , jQuery 1.4 +

 // Relatively position the div to highlight
 $('#myDiv').css({
  position: 'relative',
  top     : 0,
  left    : 0,
  zIndex  : 100
 });

 // Add overlay and make clickable
 var w = $(window).width();
 var h = $(window).height();
 var $overlay = $('<div/>', {
  'id': 'overlay',
  css: {
   position   : 'absolute',
   height     : h + 'px',
   width      : w + 'px',
   left       : 0,
   top        : 0,
   background : '#000',
   opacity    : 0.5,
   zIndex     : 99
  }
 }).appendTo('body');
 // Click overlay to remove
 $('#overlay').click(function(){
  $(this).remove();
 })
+5

, * div whatnot, not , ?

CSS, , .

+2

. , div div.

, , div . rgba, , .

, , .

. div , , , div.

0

div. -. .

CSS, highlight, :

.highlight {
  outline: 9999px solid rgba(0,0,0,0.5);
}

Javascript div:

$('#mydiv').addClass('highlight');
0

All Articles