2

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

quarks
  • 33,478
  • 73
  • 290
  • 513
xkm
  • 271
  • 2
  • 4
  • 11
  • 1
    Maybe helpful: `scrollHeight` is a property, not an attribute, and a integer, not a string. – Alexander O'Mara Jan 21 '15 at 04:24
  • This has already been answered here: http://stackoverflow.com/questions/25609506/jquery-height-outputting-same-value-as-scrollheight-on-div-with-overflowaut – jetset Jan 21 '15 at 04:28

2 Answers2

0

May this should help

 $(".pre.line-numbers")[0].scrollHeight;
Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
0

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");
quarks
  • 33,478
  • 73
  • 290
  • 513