xkm
xkm

Reputation: 271

Get scrollHeight of a DIV

I am trying to get the scrollHeight of a div with this code:

    GQuery element = $(".pre.line-numbers");
    String height = element.attr("scrollHeight");
    Window.alert(height); // empty!
    $("pre.line-numbers")
            .css("overflow-y", "hidden")
            .css("overflow-x", "auto")
            .css(CSS.HEIGHT, height + "px"); // here

But everytime, the String height is empty string.

I double checked with the browser inspector and I can see the height is there. Furthermore, to verify this, I manually set the height to a specific value, and I can see that is applied to the pre.line-numbers div

What am I missing here? What is the correct way to get the scrollHeight for all major browsers(like Firefox and Chrome)?

Upvotes: 2

Views: 605

Answers (2)

quarks
quarks

Reputation: 35346

This is the code to get the "scrollHeight" with GwtQuery:

int height = $("pre.line-numbers").get(0).getPropertyInt("scrollHeight");
$("pre.line-numbers").css("overflow-y", "hidden")
                     .css("overflow-x", "auto")
                     .css(CSS.HEIGHT, height + "px");

Upvotes: 0

Keerthivasan
Keerthivasan

Reputation: 12890

May this should help

 $(".pre.line-numbers")[0].scrollHeight;

Upvotes: 0

Related Questions