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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:45:35+00:00 2026-06-03T02:45:35+00:00

I have had a look about the site and found some code and tried

  • 0

I have had a look about the site and found some code and tried it out but its not working in any shape or form.

I am wanting to count the number of DIVs that’s placed into another DIV by the user dragging and dropping but only to count the ‘correct’ ones then if all the correct ones are in the DIV display an alert saying well done then rest the ‘game’. Also need to show how many more is needed to go to ‘win’.

This is what I have so far:

JS:

    $('.drop').each(function(){ 
        var n = $(this).children('.draggable').length;
        $(".count").text("There are " + n + " divs inside parent box detail.");
        if(n == 2){
        alert("You got them all right! :)");
        }
        });

HTML:

    <div class="foods">
              <div class="draggable" id="draggable"><img src="images/fish.png" id="draggable"></div>

              <div class="draggable" id="draggable"><img src="images/stone.png"></div>

              <div class="wrong"><img src="images/tree.png"></div>
            </div>

<div class="foods">                
<div id="droppable" class="drop">
<p>Drop here</p>
</div>
</div>

<div class="foods">
        <span class="count"></span> 
</div>

JS Fiddle of the code: http://jsfiddle.net/JRLZK/

  • 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-03T02:45:37+00:00Added an answer on June 3, 2026 at 2:45 am

    This should do it with your logic.

     $(function() {
        var n = 0;
        $( ".draggable" ).draggable();
        $( ".wrong" ).draggable();
    
        $( "#droppable" ).droppable({    
            drop: function( event, ui) {
                console.log($(ui));
                if($(ui.draggable).hasClass("draggable")){
                $( this )
                    .find( "p" )
                     .html( "Correct! :)" );
                    n++;
            $(".count").text("There are " + n + " divs inside parent box detail.");
            if(n == 2){
            alert("You got them all right! :)");
            }
    
                } else {
                        $( this )
                        .find( "p" )
                        .html( "Wrong! :(" );
                }
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a long time C# developer and have had to look at some
Apologies if this was already asked but, I have had a look and can't
I had a look on the site and on Google, but I couldn't seem
I have had a look through google results, but can't find a simple answer,
Had a look over SO but I can't see any threads which address my
I have had another question similar to this and have tried to see if
I have had Delphi 2007 for a while. I tried the Delphi 2009 trial.
I have had a talk with a friend of mine about the relative vulnerability
I have had the following problem for a while and I am really not
I've had a look around for this problem but couldn't find an answer... I

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.