Quantcast
Channel: User Ja͢ck - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Ja͢ck for How can I get the class of a parent element?

$
0
0

Your code should already work, but it might be more reliable to access the property className instead:

jQuery(function($) {  console.log($('.nav a.current').parent().prop('className'));});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script><div class="nav"><ul><li class="tab1"><a href="#1" class="current">Welcome</a></li><li class="tab2"><a href="#2">About</a></li><!-- and some lists more --></ul></div>

Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>