Skip to content

Instantly share code, notes, and snippets.

@tonthanhhung
Last active August 18, 2017 03:36
Show Gist options
  • Save tonthanhhung/4212732bde8adb4c717a1abdaf23e305 to your computer and use it in GitHub Desktop.
Save tonthanhhung/4212732bde8adb4c717a1abdaf23e305 to your computer and use it in GitHub Desktop.
sample
<body>
<ul>*
<li>Item:
<ol>*
<li>Point:
<div>
<ul>*
<li>elem1</li>
</ul>
</div>
</li>
</ol>
</li>
<li>elem2</li>
</ul>
<ul>*
<li>simple list1</li>
</ul>
<ul>*
</ul>
</body>
@lelinhtinh
Copy link

Tìm list không chứa list rồi đếm parents

var level = 0;

$('ul, ol').not(':has(ul, ol)').each(function() {
  var currLevel = $(this).parents('ul, ol').length;
  if (currLevel > level)
    level = currLevel;
});

alert(level + 1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment