Skip to content

Instantly share code, notes, and snippets.

@vladanyes
Created May 2, 2018 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vladanyes/ed35470a139d3bec2e586ea9c8f3f941 to your computer and use it in GitHub Desktop.
Save vladanyes/ed35470a139d3bec2e586ea9c8f3f941 to your computer and use it in GitHub Desktop.
// function addNewElem() {
// //adding banner element to the top of the page
// var div = document.createElement('div');
// div.className = "sale-banner--mobile";
// div.innerHTML = "BOOK NOW TO GET YOUR FIRST PICK UP FREE";
// var createdDiv = document.querySelectorAll('.sale-banner--mobile');
//
// if (window.matchMedia("(max-width: 685px)").matches && createdDiv.length <= 0) {
// document.body.insertBefore(div, document.body.firstChild);
// }
// if (window.matchMedia("(min-width: 686px)").matches) {
// for (var i = 0; i < createdDiv.length; ++i) {
// createdDiv[i].remove();
// }
// }
// }
function addNewElem() {
//adding banner element to the top of the page
var createdDiv = document.querySelectorAll('.sale-banner--mobile');
var div = document.createElement('div');
div.className = "sale-banner--mobile";
div.innerHTML = "BOOK NOW TO GET YOUR FIRST PICK UP FREE";
if (window.matchMedia("(max-width: 685px)").matches) {
document.body.insertBefore(div, document.body.firstChild);
}
for (var i = 0; i < createdDiv.length; ++i) {
createdDiv[i].remove();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment