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
  • 43,297
  • 11
  • 81
  • 105
Huma Ali
  • 1,669
  • 4
  • 36
  • 61

3 Answers3

3

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
  • 110,383
  • 23
  • 155
  • 178
1

You can use attribute selector attr("id")

$('.tab-pane.active').attr("id")
Anoop Joshi P
  • 24,863
  • 8
  • 29
  • 52
0

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

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