Get scrollHeight of a DIV

592 views Asked by At

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)?

2

There are 2 answers

0
quarks On BEST ANSWER

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");
0
Keerthivasan On

May this should help

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