Reputation: 3226
How can I get element id using the custom tag value jquery ?
<div id="1" tab_id="4" class="div_focus" tabindex="1">This is label A</div>
how can i get value of id where tab_id = 4 using jquery ?
Upvotes: 1
Views: 3050
Reputation: 732
For Wordpress users, It was tricky for me to figure out!! All I had to do is replace $
with jQuery
Working Example:
var ytid = jQuery('div[class="vi-responsive yt-light"]').attr("data-mid");
Wrong Example:
var ytid = $('div[class="vi-responsive yt-light"]').attr("data-mid");
Upvotes: 0
Reputation: 33661
Use the attributes selector
$('div[tab_id="4"]').prop('id')
or
$('div[tab_id="4"]')[0].id
Upvotes: 0
Reputation: 176896
try out this selector
$('div[tab_id = "4"]').attr("id")
check : Attribute Equals Selector [name="value"]
Upvotes: 3
Reputation: 160833
var id = $('[tab_id="4"]').attr('id');
And if there is multiple element with tab_id="4"
, and you need to get all the ids, then use:
var ids = $('[tab_id="4"]').map(function() {
return this.id;
});
Upvotes: 5