How to Make a Rule in Javascript According to DIV

Asked

Viewed 33 times

0

Good evening, guys.

I want a rule made through javascrit/Jquery that does me the following:If input with ID='A' is (INSIDE) of div with ID='B' do something... In other words, I want to know when an element is inside a certain div I can do a certain action.

  • Could clarify a little more the question. The way it is it is very difficult to know what you want.

1 answer

1


You could use getBoundingClientRect() to get a collision box and use a little math to test whether the 2 ClientRects are colliding.

Demonstration: in the codepen. You can drag the green div to see. in this rule it stays in red.

Reference link here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.