0

Hi I have this PHP function:

    function cookieNotification() {
  if (!isset($_COOKIE["ntc-cookie-policy"]) or $_COOKIE["ntc-cookie-policy"] !== "1") {
    // Set the cookie for 30 days from today
    setcookie("ntc-cookie-policy", "1", time() + (86400 * 30), "/");

    return "<div class=\"alert alert-info\" id=\"cookies\">
      <div class=\"container\">
        Council uses cookies to make this site simpler.&nbsp;
        <a tabindex=\"-2\" href=\"/category/774/cookie-policy\"><span class=\"ButtonDefault\">Find out more about cookies</span></a>
        <button onClick=\"\">Agree to cookies</button>
      </div>
    </div>";
  }
}

Its purpose is to display an alert at the top of the screen about cookie usage, and I have been asked to add a button to the div to close the div when the user clicks on the button, but I don't know how to add this functionality to this function without writing it inline in the HTML being returned, and that is bad coding practice. Does anyone have a suggestion of how to get the button to do this? Cheers.

edpo1996
  • 39
  • 5
  • 2
    This looks like PHP, not jQuery/Javascript – ADyson Aug 25 '21 at 15:41
  • Anyway there's no reason you can't write separate JS to handle the button click. What's the issue? It's hard to understand given the lack of context provided. – ADyson Aug 25 '21 at 15:42
  • 1
    Maybe this will help: [event binding on dynamically created elements](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) - In Summary: use event delegation – freedomn-m Aug 25 '21 at 15:45

0 Answers0