0

I want to check if there's an overflow in a table cell and if there's no overflow remove a class that disables scrolling in the cell. I want to to this by comparing clientHeight & scrollHeight properties. If I call $(this) I see:

enter image description here So as far as I understand I need to get the properties from the first element of the array? But when I call $(this)["0"].clientHeight or $(this).get(0) i receive a value of a child property rather than a div's in which this child resides. How can I get properties of

<div class="scrollable verticalCenterAligned">

What am I missing? Thanks!

HTML:

            <td>
                <div class="scrollable verticalCenterAligned">
                    <div class="form-group">
                        @media.Selector
                    </div>
                </div>
            </td>
            <td>
                <div class="scrollable verticalCenterAligned">
                    @Html.DisplayFor(modelItem => media.MediaRSSURL)
                </div>
            </td>

JavaScript:

$('.scrollable').each(function() {
    console.log($(this));
    console.log($(this)["0"].clientHeight);
    console.log($(this)["0"].scrollHeight);
});

</script>

ScreenShot of console:

on the screen you see that I'm getting the value of the child node property but not of the div in which this child resides. enter image description here

Dmitriy Klyushin
  • 449
  • 1
  • 4
  • 22

1 Answers1

0

I've found an answer in another post

after I wrapped my function in $(window).load(function() {}); it started showing the correct value.

Working code:

<script type="text/javascript">
$(window).load(function() {
    $('.scrollable').each(function () {
        if ($(this)[0].scrollHeight <= $(this)[0].clientHeight) {
            $(this).removeClass("scrollable");
        }
    });
});

Dmitriy Klyushin
  • 449
  • 1
  • 4
  • 22