Streaming live at 10am (PST)

Custom Tag Attributes - div

#1

Hi, I’m using Custom Attributed to push my event tracking (supported by the JS snippet inside the page settings). Usually, the buttons or single elements are straight-forward, but now I’m really struggling with setting up a click-event tracking for a block with image & text. Div contains 4 different elements and I’d like to set up an event tracking on a div level. It works on every single element separately, not on the full div though. Any ideas or tips would be really appreciated!

#2

Its better to add the API -or- js library you trying to implement (+ screenshot -and/or- read-only link + live site).

In general this how you set click event for div with webflow custom attribute named data-click and value click-me
image
image

image

js:

  1. create var and store the object
// select item
var elem = $("[data-click='click-me']");

https://www.w3schools.com/jquery/sel_attribute_equal_value.asp

  1. elem return an array (Not one element) - in this example select element 1 (position 0)
// addEventListener
elem[0].addEventListener("click", alertClick);

related:

  1. Do something
// run function when click
function alertClick() {
  alert("click");
}

Full code (copy-paste before body = after jquery load by webflow)

<script>
// select item
var elem = $("[data-click='click-me']");
// addEventListener
elem[0].addEventListener("click", alertClick);
// run function when click
function alertClick() {
  alert("click");
}
</script>
1 Like