Nitin Kabra
Nitin Kabra

Reputation: 3226

Get element id using the custom tag value jquery

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

Answers (7)

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

wirey00
wirey00

Reputation: 33661

Use the attributes selector

$('div[tab_id="4"]').prop('id')

or

$('div[tab_id="4"]')[0].id

Upvotes: 0

bipen
bipen

Reputation: 36531

use attr()

$('div[tab_id="4"]').attr('id');

Upvotes: 0

Pranay Rana
Pranay Rana

Reputation: 176896

Demo On JsFiddle

try out this selector

$('div[tab_id = "4"]').attr("id")

check : Attribute Equals Selector [name="value"]

Upvotes: 3

Sivaram Chintalapudi
Sivaram Chintalapudi

Reputation: 466

var id = $('div[tab_id="4"]').prop("id");

Upvotes: 0

Ghostman
Ghostman

Reputation: 6114

 jQuery('[tab_id="4"]').attr('id')

Upvotes: 1

xdazz
xdazz

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

Related Questions