Jesse Joseph Jesse Joseph - 4 months ago 13
HTML Question

Extract data-atribute from Current Active Tab

How is it possible to extract the

tabid
data-attribute from the current active tab:

HTML SAMPLE:

<button class="tab-page tab-active" data-tabid="Tab1">Tab1</button>

Answer

Vanilla Javascript:

Docs: .getElementsByClassName() & .getAttribute()

document.getElementsByClassName("tab-active")[0].getAttribute("data-tabid"));

jQuery:

Docs: .attr()

$(".tab-active").attr("data-tabid")

jQuery >= 1.4.3

Docs: .data()

$(".tab-active").data("tabid")
Comments