Equations in module

Asked

Viewed 89 times

2

I need to take the height of 2 elements, where these elements can have varying heights and then find the difference between the height of them as in the example:

To = 20 B = 15

|To - B| = 5

How do I do this in an equation with JS?

  • 2

    Have you ever tried to do anything? Is there a specific problem?

3 answers

11


If I understood your question correctly, it would be something like this:

function getAbsDiff(A, B)
{
   return Math.abs(A - B);
}

0

Would that be all? Could you please be more clear?

$('.elemento-1').height() - $('.elemento-2').height()
  • I found it on the net. Using the Math.abs function I can remove the difference between the two div, but it’s pretty much what’s above @Diego

  • Understood ^^

0

  • 6

    that is: Lucas' answer is correct, right? Just pass the height of the elements as parameter to the function shown in the answer. It’s nice that you try his answer and maybe mark it as accepted, since it’s essentially the same thing that’s on your fiddle. Value the people who paid attention to your question. =)

  • Correct @Elias, to tell the truth I did not get to see his post, maybe I missed an F5 on the page. now yes I read and already marked as accepted.

Browser other questions tagged

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