2

I want to get the id name from class selector. How can I do it?

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

at $(.tab-pane active) I need its id Basic

potashin
  • 44,205
  • 11
  • 83
  • 107
Huma Ali
  • 1,759
  • 7
  • 40
  • 66

3 Answers3

4

Use attr() method to get an attribute

$('.tab-pane.active').attr('id')

console.log(
  $('.tab-pane.active').attr('id')
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="tab-pane active popup_RC" id="Basic">

or get id property using prop() or get it from dom object.

$('.tab-pane.active')[0].id
// or
$('.tab-pane.active').prop('id')

console.log(
  $('.tab-pane.active')[0].id
);

console.log(
  $('.tab-pane.active').prop('id')
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="tab-pane active popup_RC" id="Basic">
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
1

You can use attribute selector attr("id")

$('.tab-pane.active').attr("id")
Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53
0

You can use .attr() to get any attribute of the element

$('.tab-pane active').attr('id');
Jayesh Chitroda
  • 4,987
  • 13
  • 18