Card links – jQuery

// makes all areas in card have one link
if ($('.card').length > 0) {
  $(".card").each(function() {
    const card = this.querySelector(".card");
    const mainLink = this.querySelector(".card-link");
    const clickableElements = Array.from(this.querySelectorAll("a")); //we are using 'a' here for simplicity but ideally you should put a class like 'clickable' on every clicable element inside card(a, button) and use that in query selector
    clickableElements.forEach((ele) =>
    ele.addEventListener("click", (e) => e.stopPropagation())
  );
  function handleClick(event) {
    const noTextSelected = !window.getSelection().toString();
    if (noTextSelected) {
      mainLink.click();
    }
  }
  this.addEventListener("click", handleClick);
  });
};

Search the site


Address

123 Main Street
Town
City
P05T C0D3

Tel: 01234 567 899

Mob: 01234 567 899

Email: ben@gomopress.com


Copyright 2023. Blah blah blah Company Limited