Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7837807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:51:22+00:00 2026-06-02T14:51:22+00:00

i want to fetch the value of data-attribute data-itemtype based on ul > li

  • 0

i want to fetch the value of data-attribute data-itemtype based on
ul > li class = "activeTab"

here is my code.

<ul class="tabs">
    <li data-itemtype="1" class="activeTab"><a href="#tab1">Published</a></li>
    <li data-itemtype="0" class=""><a href="#tab2">Unpublished</a></li>
</ul>

if class="activeTab" is in first <li> element then fetch the data attribute of first li element i.e 1 in this case and hence same applies for the second or any number of li elements.

i tried this

var itemType = $('ul.tabs').find('li.activeTab').attr('data-itemtype');

and it does not work. it shows value undefined.

Update:

i am using tabs. i want to know which tab is currently active and i need that value in javascript variable.

here is my HTML code.

<div class="widget">
    <ul class="tabs">
        <li data-itemtype="1"><a href="#tab1">Published</a></li>
        <li data-itemtype="0"><a href="#tab2">Unpublished</a></li>
    </ul>
    <div class="tab_container">
        <div id="tab1" class="tab_content">
            <div class="widget" style="margin-top:0px;">
                <div class="title"><img src="/images/icons/dark/cart3.png" alt="" class="titleIcon" /><h6>Published Items</h6></div>                          
                <p>Content</p>
            </div>
        </div>
        <div id="tab2" class="tab_content"> 
            <div class="widget" style="margin-top:0px;">
                <div class="title"><img src="/images/icons/dark/cart3.png" alt="" class="titleIcon" /><h6>Unpublished Items</h6></div>
                <p>Content</p>
            </div>
        </div>
    </div>  
    <div class="clear"></div>        
</div>

the jQuery being used is this.

$.fn.contentTabs = function(){ 

        $(this).find(".tab_content").hide(); //Hide all content
        $(this).find("ul.tabs li:first").addClass("activeTab").show(); //Activate first tab
        $(this).find(".tab_content:first").show(); //Show first tab content

        $("ul.tabs li").click(function() {
            $(this).parent().parent().find("ul.tabs li").removeClass("activeTab"); //Remove any "active" class
            $(this).addClass("activeTab"); //Add "active" class to selected tab
            $(this).parent().parent().find(".tab_content").hide(); //Hide all tab content
            var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
            $(activeTab).show(); //Fade in the active content
            return false;
        });

    };
    $("div[class^='widget']").contentTabs(); //Run function on any div with class name of "Content Tabs"

the above code does not work for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:51:24+00:00Added an answer on June 2, 2026 at 2:51 pm

    Seems to be working fine.

    I would use .data(...) instead:

    var itemType = $('ul.tabs').find('li.activeTab').data('itemtype');
    alert(itemType);
    

    Fiddle: http://jsfiddle.net/maniator/2GYxh/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to fetch the value from dynamically created textfield with tag from NSMutableArray.... Txt_New_Estimated
I want to add and fetch the value from dynamically created textfield with tag
I am using this code to fetch the core data results: -(void)getData { NSEntityDescription
I want to fetch a data from two tables even if the second table
I want to store values as key,value,value pair. My data is of type Key
I want to pull data from table Province_Notifiers and also fetch all corresponding items
Suppose I have one button, and I want it to fetch data (like an
I want to fetch data from json array using java gson library following is
I want to fetch NULL values in Mysql . My query is like this-:
I want fetch last record using hibernate criteria Can u help me?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.