0

I had a function that shoot when I click on the bottom part of my div. I don't know how I can implement this.

Below a part of my code:

  filha1.addEventListener("click", cliclouEmBaixo( event, filha1) )

  function cliclouEmBaixo(event, divElement) {
        const clickY = event.clientY;  // coordenada y do click
        const divBottom = divElement.offsetTop + divElement.offsetHeight;  // coordenada y da div     + valor absoluto da altura da div
        const labelDesejado = divElement.children[0]
        const inputDesejado = divElement.children[1]
        // Verifica se o clique ocorreu na parte de baixo da div
        if (clickY >= divBottom) {
          console.log('Clicou na parte de baixo da div!');
          // Insira a ação que deseja realizar aqui
             input.classList.contains('marcado')? ' ': modificandoComDiv(labelDesejado, inputDesejado)
        }
      }

I want to know how to call my function cliclouEmBaixo with a click

When I call my function in the way that I write above nothing happens.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Azure.736
  • 1
  • 1
  • 1
    An easier option might be to position another element relative to this, covering the clickable area, and listen for events on that (It would depend on the structure of the element and what else you need to support) – DBS Jul 24 '23 at 13:23
  • The first line of code shown is executing `cliclouEmBaixo` exactly once and then setting `undefined` as the actual click handler. – David Jul 24 '23 at 13:25
  • 1
    You're assigning the result of calling `cliclouEmBaixo` to the event listener for the click event of `filha1`. You could solve this by just using `filha1.addEventListener("click", cliclouEmBaxio)` and changing `cliclouEmBaixo` to only take `event`, and set `divElement` to `event.target`. – Heretic Monkey Jul 24 '23 at 13:29
  • I try with others elemenst, hr for example, but i had some problems with and for this i decide to use the border of my div to make this divisory line – Azure.736 Jul 24 '23 at 13:36

0 Answers0