Huma Ali Huma Ali - 4 months ago 5x
Javascript Question

How to get an element's id from its classname

I want to know how can I get the id of an element based on a specific class name? In the following

I want to retrieve the
of the div having class
tab-pane active

<div class="tab-pane active" id="Basic">


Use .attr() as shown :-

var id = $('').attr('id')


var id = $('').attr('id')

Side Note :- I am assuming that you have only one element with class tab-pane active in your DOM otherwise you have to use $.each() to loop through all div with class tab-pane active