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

  • SEARCH
  • Home
  • 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 771957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:44:09+00:00 2026-05-14T18:44:09+00:00

This question is in continuation to How to get attributes of container in jQuery

  • 0

This question is in continuation to How to get attributes of container in jQuery, I have different containers on my webpage and all of them have <div id = "some values">. Now how can I get attributes values separately for each component?

Is there any way I can know which attribute id belong to which container div?

Currently I am using:

var id = $( '.promotion' ).attr( 'id' );

But if I have multiple promotional components on page and all have same div attribute as id than how can I relate that this particular attribute id belonged to this specific container?

Update: I am having a function which is called for each container present on the page and so if I am using above mentioned code than will it not always return me the first match for id in the div and would never go to other divs and so I will always get same value for id which is for the first container ? If so than what is the work around for this ?

var id = $( '.promotion' ).this.attr( 'id' );

var id = $( '.promotion' ).$this.attr( 'id' );

var id = this.$( '.promotion' ).attr( 'id' );

How would I know if the attribute value is for current container, so how should I use this properly to get this information ?

Hope this question is clear.

  • 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-05-14T18:44:09+00:00Added an answer on May 14, 2026 at 6:44 pm

    You can loop through and process each div individually

    $(".promotion").each(function() {
        var id = this.id; // 'this' is the html element, not the jquery object
    });
    

    Update

    function myfunc() {
       alert(this);
    }
    
    // inside myfunc, this will be the window
    myfunc(); 
    // call (also: apply()) changes "this" to be the first argument
    myfunc.call(document.getElementById("someid")); 
    

    Jquery uses this to refer to the current element being processed. In events that would be the target element. In .each it is the current element in the collection.

    Consider:

    $(".promotion").click(function() { 
       alert(this); // will alert with the div that was clicked
    });
    

    In Jquery you can wrap any html element with a JQuery Object by using $(element). So when this is an html element like in the example above you can use $(this):

    $(".promotion").click(function() { 
       alert($(this).attr("id")); // will alert with the div that was clicked
    });
    

    Play around with it here: http://jsbin.com/okuri3/edit.

    More about this:

    • http://www.quirksmode.org/js/this.html
    • http://remysharp.com/2007/04/12/jquerys-this-demystified/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a continuation of this question I'm wondering if I can get some simple
This is a continuation of the question here: JBoss - does app have to
In continuation of the question at this link I wanted to add some functionality
This is sort of a continuation of this question . I have a file
This is a continuation to this question which Oleg has answered. I have 2
This a continuation of this question. I have an Address class which contains basic
This is a continuation of the project outlined in this question. I have the
This is a continuation of my question: How to get reverse of a series
This is a chronological continuation of this question. I have simplified my board so
This question is a continuation of my previous question here zend models architecture (big

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.