I am trying to change Bootstrap backdrop opacity using JS or jQuery (Bootstrap 4.6):
// JavaScript
let modalBackdrop = document.getElementByClassName("modal-backdrop");
modalBackdrop.style.opacity = "0.9 !important";
or
// jQuery
let modalBackdrop = $(".modal-backdrop");
modalBackdrop.css("opacity", "0.9 !important");
I want to do it with JS because I have a few modals and I want to change it only for a specific modal.
When I console log the modalBackdrop
data, it shows the backdrop element so it’s the correct selector
2
Answers
You have to remove
!important
:or
You need to set style attribute:
Try this:
JS:
jQuery: