What is the best way to enable the user to keep clicking up to a specific limit?

Find the JSFiddle link here: http://jsfiddle.net/jbirdwell/YEmat/1/

The HTML structure:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css" />
        <script src='script.js'></script>
        <title></title>
    </head>
    <body>
        <table>
            <tr>
                <td>
                    <img src = "http://www.nba.com/media/playerfile/thunder_logo.gif"/><img id="champion" src="http://farm5.staticflickr.com/4018/4624684843_1630196e78.jpg"/><div id="ball"></div>&nbsp;<div id="ball"></div>&nbsp;<div id="ball"></div> <div id="ball"></div> <div id="ball"></div> <div id="ball"></div> <div id="ball"></div> <div id="ball"></div> <div id="ball"></div> <div id="ball"></div> <div id="ball"></div>  
                </td>
            </tr>
        </table>

    </body>
</html>

JavaScript functionalities:

var ball = 11;

$(document).ready(function() {
    $('#ball').click(function(){
        $(this).fadeOut();
        ball -= 1;
        if(ball === 0){
            $('#champion').css("display",'inline-block');
        }
    });


});

Customized CSS properties:

#ball{
        background-color: orange;
        height: 30px;
        width: 30px;
        border-radius: 100%;
        border: 1px solid #FF8A21;
        display: inline-block;
}
#champion{
    display: none;
    width: 45px;
    }

I have some queries regarding this code.

How can I make sure that all the #ball elements fade out until they are completely gone?

Is there a way to replicate the basketball instead of manually adding each one?

Answer №1

Modify the identifier to a category. It seems like the current setup is causing issues because only one ID can be used at a time. Take a look at this interactive demonstration for reference: http://example.com

$('.circle').click(function()

  <div class="circle"></div> 

I'm not entirely clear on your second inquiry. Are you asking about dynamically incorporating circles instead of statically coding them?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

tagit: update the label's value

I've been utilizing the jquery ui plugin https://github.com/aehlke/tag-it to incorporate tagging functionality into my project. This is how I am creating tags: $("#Input").tagit("createTag", "ABC"); My goal is to append additional text to the labe ...

I'm feeling perplexed. What's the correct way to implement CSS in this situation?

So I have a widgets sidebar and I've styled it with padding of 10px like this: .widgets ul {padding: 10px} However, there is one specific UL inside the widgets that I want to exclude from this padding rule while keeping all other ULs with the defaul ...

Floating Div at the lower part of the page similar to the one in Facebook Messenger

Can anyone help me find a CSS or jQuery method to keep a div pinned at the bottom of the screen, similar to how it's done on Facebook when viewing individual message conversations? The "Reply" box always stays at the bottom and moves up as you scroll ...

Sum text input in a table using jQuery

Whenever the add button is clicked in my code, a new row is generated in the table. I am looking to have each row update the subtotal value automatically when the quantity or price input fields are modified. HTML <table width="100%" border="0" > ...

What could be the reason behind the overlap between this input selector and its label?

I am encountering a problem with a search form that contains code not authored by me. The issue lies in the input selector being obscured by its label. It is evidently a CSS-related matter, yet I have been unable to pinpoint the exact styling causing thi ...

Django does not support CSS styling out of the box

My webpage is rendering HTML correctly, but the CSS styles are not being applied. I am currently in development mode and running the django dev runserver. STATICFILES_DIRS = ("C:/Users/user/site/sitemain/static",) STATIC_ROOT= '' STATIC_URL = ...

Finding the index number of a DIV element when it is clicked

Here is an example of the HTML structure I am working with: <div id="preview-wrapper"> <div class="dz-preview dz-image-preview"> <a class="rotate-a" href="javascript:void(0);"> <img class="rotate" src="public/a ...

Develop a MySQL table using AJAX and HTML within a Cordova application

I've been developing an app using Cordova and I'm looking to create a feature where users can create and join different rooms to perform various actions. Despite trying multiple tutorials and scouring the internet, I'm struggling to understa ...

The Gear S device is experiencing issues transmitting data through a POST request, and no error message is being

Currently, I am in the process of creating a Gear S application (and eventually for S2) that gathers data and forwards it to my server using a POST request. Below is snippet of the code responsible for sending the data: $.post(URL_POST_DATA, { ...

Enhance SVG styling by using CSS as the background

Is there a way to access SVG using CSS when using them like this? .logo { ... background-image: url("../VectorImages/logo.svg"); } I came across some scripts that claim to convert svgs to inline SVG, making them accessible for CSS. I tried it and it wo ...

web browser freezing when trying to open bigger files

I have a project where I need to download multiple JSON data files and visualize them using D3 data charts. However, when the page loads, it takes around 2-3 minutes to download and visualize the files, especially on mobile devices. This causes the browser ...

Clicking on the expand button will render the content inside the <p:panel>

My current frontend using JSF loads an excessive amount of data, not always necessary for the user. This data is categorized by tags and I want it to be rendered dynamically with a click on an expand panel: <p:panel header="#{myBean.someStringT ...

Designing the Background with HTML and CSS

Can someone assist me with customizing the background of my website? I would like to achieve the following specifications: Implementing different gradient backgrounds on the left and right sides of the website, ensuring compatibility with all Internet Ex ...

Achieving functionality with dropdown menus in jQuery

I am facing an issue with a dropdown menu that works perfectly in jsFiddle during testing, but does not function as expected when I run it on my testing server. jsFiddle: http://jsfiddle.net/cyberjo50/39bu8/2/ HTML <!doctype html> <html> < ...

Preserve the aspect ratio when using horizontal flex cards

I have successfully created a vertical flex card with an image on top that maintains a 16:9 aspect ratio at all times. Here is the code for my vertical flex card: .card { display: flex; flex-direction: column; margin: 0.75rem; } .card .card ...

Creating Filled DIVs using JavaScript

Although it may appear to be a common inquiry, my specific needs have not been addressed in any of the Stack threads I've come across. I am dealing with a series of nested DIV statements, as demonstrated here (not all CSS included). I am looking to ...

What is the best way to duplicate this content from a picture using CSS?

Trying to replicate text in an image using HTML and CSS. Wondering if there's a better way than setting each line with its own font size. Here's the image I'm working on: https://i.sstatic.net/bMPhy.png Current issues with the approach: ...

The clash between mototools and JavaScript is causing both to be non-operational

I am currently facing a conflict between JavaScript and Mototools in my project. I have heard about the NoConflict script, but I'm not sure how to implement it properly. I will provide the code for both dependencies so that someone can explain it to m ...

Using PHP to create a dynamic gallery that changes styles when hovering with CSS

One of my past projects involved creating an image gallery with CSS that had some unique features: I created a thumbnail gallery I placed 1x1 pixel images in a div On mouseover of the thumbnails, the 1x1 pixel images expanded to fit the div size, with th ...

Retrieve Header information when making a cross-domain AJAX request

I've been working on a way to validate image URLs by using an AJAX call to check if the image is still available. The challenge I'm facing is that the image server is on a different domain, so I included the crossDomain: true attribute in my AJAX ...