const section = document.querySelectorAll('.content-main-category-title-container'); console.log("3",section); var sections = {}; Array.prototype.forEach.call(section, function(e) { sections[e.id] = e.offsetTop; }); const financeAnchor = document.getElementById("finance-anchor"); const salesAnchor = document.getElementById("sales-anchor"); const serviceAnchor = document.getElementById("service-anchor"); // const tradeAnchor = document.getElementById("trade-anchor"); // const autoGearAnchor = document.getElementById("autoGear-anchor"); // const partsAnchor = document.getElementById("parts-anchor"); const dropdownValue = document.getElementById("sidebar-dropdown"); let protectionPlanLink = document.querySelector('#protection-plan-link'); let wbycLink = document.querySelector('#wbyc-link'); let carcareLink = document.querySelector('#carcare-link'); let whyServiceWithUsLink = document.querySelector('#why-service-with-us-link'); let dealersLinks = document.querySelectorAll('.dealersLink'); var anchors = [ financeAnchor, salesAnchor, serviceAnchor // tradeAnchor, // autoGearAnchor, // partsAnchor ]; protectionPlanLink.addEventListener('click', function() { tealiumEventClick('an_protection_plans_page_click', protectionPlanLink.innerHTML); }); wbycLink.addEventListener('click', function() { tealiumEventClick('wbyc_page_click', wbycLink.innerHTML); }); carcareLink.addEventListener('click', function() { tealiumEventClick('car_care_page_click', carcareLink.innerHTML); }); whyServiceWithUsLink.addEventListener('click', function() { tealiumEventClick('why_service_with_us_lp_click', whyServiceWithUsLink.innerHTML); }); for(let i = 0; i < dealersLinks.length; i++) { dealersLinks[i].addEventListener('click', function() { tealiumEventClick('an_dealers_click', dealersLinks[i].innerHTML); }); } financeAnchor.addEventListener('click', function(e) { removeAllActive(anchors); makeActive(financeAnchor); }); salesAnchor.addEventListener('click', function() { removeAllActive(anchors); makeActive(salesAnchor); });; serviceAnchor.addEventListener('click', function() { removeAllActive(anchors); makeActive(serviceAnchor); });; // tradeAnchor.addEventListener('click', function() { // removeAllActive(anchors); // makeActive(tradeAnchor); // });; // autoGearAnchor.addEventListener('click', function() { // removeAllActive(anchors); // makeActive(autoGearAnchor); // });; // partsAnchor.addEventListener('click', function() { // removeAllActive(anchors); // makeActive(partsAnchor); // });; const makeActive = function(link) { link.classList.add('active'); } const removeActive = function(link) { link.classList.remove('active'); } const removeAllActive = function() { for(var i = 0; i < anchors.length; i++) { removeActive(anchors[i]); } // Array.prototype.forEach.call(anchors, anchor => { // removeActive(anchor); // }); } dropdownValue.onchange = function() { window.location.href = this.value; }; function tealiumEventClick(event, eventLabel) { let clickdata = { "category_l1":"MLP", "category_l2":"FAQ", "category_l3":"Frequently Asked Questions", "category_l4":"(not set)", "event":"" + event, "event_category":"EngagementType", "event_action":"EngagementType_MLP|||Click", "event_label":"" + eventLabel, "event_value":"1", "pagegroup":"mlp" }; window.utag_data = clickdata; window.utag.link(window.utag_data); }