If you want to change the rgba css property using javascript, you will need to use the replace method, however you can improve your code as follows:
CSS
div { background-color: rgba(100, 100, 100, 1.0); }
Js
function addAlphaChannel() {
var oldBGColor = $('div').css('background-color'),
newBGColor = oldBGColor.replace(/[^,]+(?=\))/, '0.8');
$('div').css({ backgroundColor: newBGColor });
}
Hope this helps you.
source
share