$(document).ready(function() { $(".colorcar_wrap .color_car:not("+$("p.colorchip > a.selected").attr("href")+")").hide(); $(".colorchip > a").click(function(){ $(".colorchip > a").removeClass("selected"); $(this).addClass("selected"); $(".colorcar_wrap .color_car").hide(); $($(this).attr("href")).show(); /* * Fire javascript custom event. Set the Dtm rule with same event name. * */ var selectColor = $(this).attr('href').replace('#', ''); var dtm_event = new CustomEvent("vehicle-content-color-selection", { detail: { color: selectColor, vehicle: curVehicle, type: curType } }); //console.log(selectColor + " : " + curVehicle + " : " + curType); document.body.dispatchEvent(dtm_event); return false; }); });