Set transparency of a DIV and its contents using jQuery

后端 未结 4 1086
心在旅途
心在旅途 2021-02-18 18:15

What is the best way to set the transparency of a HTML DIV element and its contents using jQuery?

4条回答
  •  一整个雨季
    2021-02-18 18:36

    $('#my_element').css({ 'opacity' : 0.7 });

    Do you want to actually set the opacity to each of the contained elements as well, or you just want it to 'appear' as if the child elements have the same opacity?

    As an example to my question, if you wanted something that sets an element, and each of the children elements, you could do something like this

    html

    lorem
    ipsum

    jquery

    $('#my_element').children().
                     css({ 'opacity' : 0.25 }).
                     end().
                     css({ 'opacity' : 0.25 });
    

    Hope this helps. Cheers.

提交回复
热议问题