Trying to update the "background-image:" of a CSS class upon button click.
JQuery:
$(function() {
$('button').on('click', function() {
$('.masthead2').css('background-image', 'url("../img/whiteheader.png")');
});
});
CSS:
.masthead2 {
position: relative;
width: 100%;
height: auto;
min-height: 35rem;
padding: 15rem 0;
background-image: url("../img/roseheader.png");
background-position: center;
background-repeat: no-repeat;
background-attachment: scroll;
background-size: cover;
}
After clicking the button, the "background-image:" from the CSS style is cleared and the HTML changes like this:
<header class="masthead2">
Changes to:
<header class="masthead2" style='background-image: url("../img/whiteheader.png");'
Despite the change in HTML, the new image does not display on the page. Even though the URL seems correct as loading it directly into the CSS works fine.
Directly updating the background-image in the CSS should resolve the issue.