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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:27:41+00:00 2026-06-09T17:27:41+00:00

I am using a bit of jquery and javascript mashed up in this weird

  • 0

I am using a bit of jquery and javascript mashed up in this weird hodgepodge of code.

var SELECTED_ELEMENT;  //this ends up being a JS array of ELEMENTS like the following line.
SELECTED_ELEMENT.push($(this).closest(".draggable"));
//Now i wanted to select stuff
$(".draggable").click(function(){
   var found = 0;
   for (var i = 0; i < SELECTED_ELEMENT.length; i++){
      if(SELECTED_ELEMENT[i] == this){
         found = 1;
      }
   }
   if(found == 1){
      alert("yep");
   }else{
      alert("nope");
   }
});
//this doesnt seem to do what i want.

The question at hand is that this is never returning true, even when it is. I was just trying to find a way to in javascript search the array for it. You would think that a simple search through the array would figure it out, but possibly an improper reference to ‘this’

  • 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-09T17:27:43+00:00Added an answer on June 9, 2026 at 5:27 pm

    There are some issues, like int found = 0 which isn’t even javascript. Then you are pushing jQuery objects to an array, and comparing them to dom elements.

    Push the elements instead:

    var selectedElements = [],
    
        closest = $(this).closest(".draggable")[0];
    
    if( closest ) {
        selectedElements.push( closest );
    }
    
    $(".draggable").click( function() {
        var index = selectedElements.indexOf(this);
    
        alert( index > -1 ? "yep" : "nope" );
    });
    

    demo: http://jsfiddle.net/sqj42/

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

Sidebar

Related Questions

I am using this bit of code successfully: $(window).bind('resize',function() { window.location.href = window.location.href; });
I've been using quite a bit of JQuery, KnockoutJS and other JavaScript stuff for
We are using JQuery and some bit of Javascript in our project. We are
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I'm having a bit of a difficulty using jQuery to bind a function to
I'm using the tag-it library for jquery to make a tagging system (a bit
I'm having a bit of trouble with jQuery Deferred. I'm using a jQuery ajax
I am trying to call to the bit.ly URL shortening service using jQuery with
I'm using the bit.ly url shortening service to shorten certain url's being sent to
I am using a bit of borrowed code, and am concerned for its vulnerability

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.