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
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
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">
You can use attribute selector attr("id")
$('.tab-pane.active').attr("id")
You can use .attr()
to get any attribute of the element
$('.tab-pane active').attr('id');