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 6057633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:30:36+00:00 2026-05-23T08:30:36+00:00

I have a series of divs: <div class=some_class active>Some Content</div> <div class=some_class>Different Content</div> <div

  • 0

I have a series of divs:

<div class="some_class active">Some Content</div>
<div class="some_class">Different Content</div>
<div class="some_class">More Different Content</div>

(active class changes dynamically)

Each has been assigned to data of an image element thusly:

$("div.some_class").each(function(){
        current = $(this);

        $('div#images').append('<img class="link new" src="/style/images/image.png" />');
        $(".link.new").removeClass('new').data('project', current);
    });

I want to use this function to compare the active element to those stored in data:

function live_test(){

        active = $("div.some_class.active");
        $("#images img.link").each(function(){

            if ($(this).data('project') == active){
                $(this).addClass("active");
            }
        });
    }

The intention being to add a class of active to the image that holds the same div.some_element as the one that has the active class, but this function returns false all the time, never finding a match. I am pretty sure I am missing a fundamental here, but what? And is there any other way to do it?

  • 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-23T08:30:37+00:00Added an answer on May 23, 2026 at 8:30 am

    You are comparing 2 jquery objects. These objects will never be the same. What you want to compare are the elements within the jquery objects. Assuming both can only ever have one element, do this:

    if ($(this).data('project')[0] == active[0]){
    

    Edit:
    While the above should answer your question, why not do the reverse of what you’re doing. Rather than store the element on the image, store the image (or id of the image) on the element. Then you can easily grab the image related to the given element. You want to avoid looping when possible.

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

Sidebar

Related Questions

I have a series of divs like this: <div id=available-posts> <div class=post id=unique_id> <a
I have a page with a series of divs. Each div represents a slide
I have a series of DIVs on a page which each contain a nested
I have a series of divs in a pattern of header/body, where a click
I have a series of divs that are hidden and I would like to
I have a page that has three divs one at the top, one at
I'm having a minor css issue. I have a series of layered divs and
I'm looking to click a.go and then have a series of divs all with
I have a layered div component which displays a successive series of large kb
A quick question. I have a series of DIVs with the following classes .level1

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.