Robert
Robert

Reputation: 114

How to Add and subtract var in Jquery?

I'm a completely nooby on Jquery. I'm trying to calculate and obviously didn't work.

$(document).ready(function() {
    var x = $('.a').height();
    var y = $('.b').height();
    $('.c').height(y - x + x);

});

I'm close to make it work? :))

https://jsfiddle.net/kav5y0vf/

Upvotes: 0

Views: 153

Answers (2)

Rafdro
Rafdro

Reputation: 790

Instead of:

var x = $('.a').height();

Use

var x = $('.a').outerHeight();

height() returns height of element with no padding, whereas outerHeight() does.

jsfiddle below:

https://jsfiddle.net/kav5y0vf/2/

Upvotes: 3

Georgiy Dubrov
Georgiy Dubrov

Reputation: 410

Change this line

$('ul.logad li.o').height(y - x + x);

To

$('ul.logad li.o').css('height', (y - x + x) + 'px');

Don't know why you need this but y-x+x = y

Upvotes: 1

Related Questions