0

I´m using $(this).find("ul").filter(":first").height(); to get first ul.

But the height is not defined, then the height is -20

My ul:

ul style="width: 252px; min-width: 820px; padding-bottom: 20px;" class="jqx-tree-dropdown-root"

Best Regards.

Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188

2 Answers2

0

I created a quick jsFiddle which displays rather well that your code should work just fine. However you are probably using "this" incorrectly :)

https://jsfiddle.net/qoxub22u/

Html mockup

<div class="container">
  <h5>First one has height of 40px</h5>
  <ul style="height:40px">
    <li>Test</li>
    <li>Test1</li>
  </ul>

  <h5>Second one has height of 70px</h5>
  <ul style="height:70px">
    <li>Test</li>
    <li>Test1</li>
    <li>Test2</li>
    <li>Test3</li>
  </ul>
</div>
<button id="submit">Get height</button>

Jquery part

$( "#submit" ).click(function() {

    /* Replace .container with ur this selector */
  var height = $('.container').find("ul").filter(":first").height();

  alert(height);
});
user2831723
  • 832
  • 12
  • 25
  • $(this) is a div. $(this) is the same: var self = $(this); alert(self.find("ul").filter(":first").height()); The UL height is not defined. – Gabriel Costa Alves Aug 08 '16 at 14:34
  • It seems like you don't very clearly understand how $(this) works. It's rather well explained in here - http://stackoverflow.com/questions/1051782/jquery-this-vs-this – user2831723 Aug 08 '16 at 15:48
  • Hi, this is not problem. My code: var treeViews = $(selector).find(".treeview"); treeViews.each(function () { var self = $(this); alert(self.find("ul").filter(":first").height()); } – Gabriel Costa Alves Aug 08 '16 at 16:15
0

$(this) is a div.

$(this) is the same:

var self = $(this); alert(self.find("ul").filter(":first").height());

The UL height is not defined.