eozzy
eozzy

Reputation: 68680

changing value type

$.fn.findMaxHeight = function() {
    var wrapperHeight = $(this).height();
    var wrapperMaxHeight = $(this).css('max-height');

    if ( wrapperHeight == wrapperMaxHeight ) {
        alert("max-height reached");
    } else {
        alert("not yet");
    }
}
$('.subscription-wrapper').findMaxHeight();
$('.payment-wrapper').findMaxHeight();

... doesn't work because .css() returns 300px and .height() returns 300 so they can't be compared. how do I fix it?

Upvotes: 0

Views: 45

Answers (3)

nil
nil

Reputation: 3631

Just use parseInt.

Specifically,

var wrapperMaxHeight = parseInt($(this).css('max-height'), 10);

Upvotes: 4

Janus Troelsen
Janus Troelsen

Reputation: 21300

Use parseFloat instead of parseInt. The height is not always an integer! Half-pixels are possible.

Upvotes: 0

sdespont
sdespont

Reputation: 14025

Convert your CSS height using parseInt

var wrapperMaxHeight = parseInt($(this).css('max-height'));

Upvotes: 0

Related Questions