The nuSelectable plugin enhances the functionality of jQuery

I am currently experimenting with the jQuery nuSelectable plugin in order to enable users to select multiple items simultaneously. Unfortunately, I am encountering difficulties in making the selection work as intended. You can find the plugin here.

After selecting items, they should change color, but nothing happens when I click on them. What could be causing this issue?

Here is the HTML code:

        <div id="item-container" class="text-center">
        <div class="row element-medium-top element-medium-bottom">
            <div class="selectIconBox ">
              <div class="item iconWrap">1</div>
              </div>
              <div class="selectIconBox ">
                  <div class="item iconWrap">2</div>
              </div>
              <div class="selectIconBox ">
                  <div class="item iconWrap">3</div>
              </div>
              <div class="selectIconBox ">
                  <div class="item iconWrap">4</div>
              </div>
            </div>
        </div>

This is the CSS code:

.iconWrap-selected {
    background-color:#6a989e;
}
.iconWrap {
    border: 2px solid #101820;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    padding: 17px;
    margin-bottom:10px;
    font-size: 1.25em;
    color:#101820;
    position:relative
}
#item-container .iconWrap {
    cursor: pointer;
    transition: all 0.3s ease-in-out 0s;
}
.selectIconBox {
    display: inline-block;
    margin: 40px 80px;
}

Lastly, here is the JS code:

<script src="../assets/js/jquery.nu-selectable.js"></script> 
<script>
$('#item-container').nuSelectable({
  items: '.item',
  selectionClass: 'selectIconBox',
  selectedClass: 'iconWrap-selected',
  autoRefresh: true
});
</script>

Your assistance with this matter would be greatly appreciated.

Answer №1

I believe you are looking for something like this:

1) Include the .selectable class along with your .selectIconBox class in your HTML.

2) Delete your JavaScript code and

.iconWrap-selected { background-color:#6a989e;}
from the CSS.

3) Add

.selectable .ui-selected { background: #F39814; color: white; }
to your CSS.

4) Replace your existing jQuery with $( ".selectable" ).selectable();.

Note : You can modify the background-color of the selected item by changing the value in the .ui-selected class in your CSS. However, you cannot change the name of that specific class (i.e. .ui-selected).

Source: JQuery User Interface

Update :

Follow Up Answer: As mentioned in the comment below.

$(".selectable").selectable();

// On click event for .submit class or any other defined class.

$(".submit").click(function()
{
  var selectedArr = []; // Initialize an Array

  $(".selectable").each(function() // Find each element with the .selectable class 
  {
    var selectedNum = $(this).find('.ui-selected').text(); // Find the text inside the .ui-selected class
    var intNum = parseInt(selectedNum); // Convert it to an Integer
    if (!isNaN(intNum)) { // Check if it is a number and then add to the array
      selectedArr.push(intNum);
    }    
  });
  alert(selectedArr); /* The Array "selectedArr" now contains the selected numbers */
});
.iconWrap {
    border: 2px solid #101820;
    border-radius: 50%;
    width: 70px;
    height: 70px;
    padding: 17px;
    margin-bottom:10px;
    font-size: 1.25em;
    color:#101820;
    position:relative
}
#item-container .iconWrap {
    cursor: pointer;
    transition: all 0.3s ease-in-out 0s;
}
.selectIconBox {
    display: inline-block;
    margin: 20px 80px;
}

.selectable .ui-selected { background: #F39814; color: white; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<div id="item-container" class="text-center">
  <div class="row element-medium-top element-medium-bottom">
    <div class="selectIconBox selectable">
      <div class="item iconWrap">1</div>
    </div>
    <div class="selectIconBox selectable">
      <div class="item iconWrap">2</div>
    </div>
    <div class="selectIconBox selectable">
      <div class="item iconWrap">3</div>
    </div>
    <div class="selectIconBox selectable">
      <div class="item iconWrap">4</div>
    </div>
  </div>
</div>

<button class="submit">Submit : Alert! Selected</button> 

Answer №2

To accomplish this, utilize jQuery UI.

Take a look at this straightforward code snippet.

Here is the HTML structure:

<div>
<ul class="items">
    <li class="item">1</li>
    <li class="item">2</li>
    <li class="item">3</li>
    <li class="item">4</li>
    </ul>
</div>

JavaScript part:

$(".items").selectable({filter:"li"});

Cascading Style Sheets (CSS):

.items{
    width:400;
    height:500;
    overflow:auto;
}
.item{
    color:#fff;
    height:100px;
    width:100px;
    border-radius: 50%;
    background:cyan;
    margin:15px;
    text-align:center;
    float:left;
    list-style:none;
}
.ui-selected{
    background-color:green !important;  
}

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

Uploading an Array of Files Using Ajax and PHP is Not Being Received by the .php Script

I'm trying to send an array of files from a form to a .php file, but it seems that the PHP file is not receiving the files I'm uploading. Here's my HTML code: <form id="contact-form" autocomplete> <fieldset id="aboutYo ...

Display a single video on an HTML page in sequential order

My webpage contains a video tag for playing online videos. Instead of just one, I have utilized two video tags. However, when attempting to play both videos simultaneously, they end up playing at the same time. I am seeking a solution where if I start pla ...

Interactive dropdown menu that scrolls upon clicking

Is there a way to make the page automatically scroll down to the bottom of a dropdown menu when it is clicked? Currently, users have to manually scroll down after opening the menu. I initially tried using anchors for this functionality, but it interfered w ...

Discover the CSS auto height value using JavaScript

Is there a way to utilize JavaScript in determining the value set for auto height in CSS? My development stack includes Grails and jQuery. For instance, consider the following CSS: .tool-preview { height: auto; } ...

Fullcalendar not displaying any events

As a beginner programmer, I'm struggling to make this code work (sourced from here). It's using MySQL to store data, and while I want to grasp all its components, my understanding of ajax and jQuery is still in its early stages. The code depends ...

What is the best way to integrate Angular 5 with various sources of JavaScript code?

I am fairly new to angular. I am looking to merge an external angular script file and on-page javascript code with angular 5. I understand that angular does not typically allow for the inclusion of javascript code in html components, but I believe there m ...

A web application using JavaScript and Node.js with a focus on creating a REST

After extensive research, I am eager to develop a web application using JavaScript and Node.js with an SQL back-end. However, the abundance of frameworks and tools available has left me feeling overwhelmed. While I have identified some that I would like to ...

tag of data in jquery

Here is how my setup looks: <div onclick="EditCalendarEvent('@_schedulerEvent.SchedulerID','@_schedulerEvent.SchedulerItemID', event)" class="ScheduleEvent_Draggable ScheduleEvent" data-schedulerID="@_schedul ...

Ensure that the responsive SVG image remains centered even when resizing

I have been attempting to center crop the responsive SVG image while resizing. Even though I used preserveAspectRatio="xMidYMax slice", the image width does not stay consistent with my screen size. body{ margin:0;padding:0; } .wrapper { position: re ...

Unused sizing attributes in IMG tags

I can't seem to figure out what's going wrong here... I want the image tag to initially display the 250px wide "small" image, and then allow the browser to select the most suitable image using the srcset and sizes attributes - essentially, the " ...

How to style a div's height responsively behind a circle using CSS

Can a CSS pattern be created with responsive design, ensuring that the background line is always in the correct position and height regardless of window size? https://i.sstatic.net/27Tf2.jpg ...

The Vue.js component is only refreshing after I manually refresh the browser page

As a newcomer to Vue.js and other reactive frameworks, I am still learning the ropes. I have a component that needs to update whenever there is a change. The goal is to display a balance from a specific login. <li :key="balance">Balance {{ balance ...

Creating a custom arrow design for a select input field using CSS

I'm currently developing a website (using Wordpress with a custom theme) and I want to incorporate an up/down arrow in the select input field using CSS. The HTML code I have for creating the up/down arrow in the select input field is as follows: < ...

Ready document not triggering at the anticipated time

I've developed a website where all the pages are loaded using ajax. When I load the first page, I check if jQuery is loaded by using: if (window.jQuery) { alert('jQuery is loaded'); } Every time this script runs, it successfully alert ...

What is the best way to organize React components that need to retrieve data from a modal?

At this moment, my React container is structured like so: class TableData extends Component { some React Functions and state changes. <Sidebar passdata as props/> } Within the Sidebar component, there is a modal that needs to update the state of b ...

Using Three.js to Manipulate Objects through Their Names

Is there a way to access multiple meshes with the same name? var mesh1 = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0xffffff })); mesh1.name = "meshes"; scene.add( mesh1); var mesh2 = new THREE.Mesh( geometry, new THREE.MeshBasicMate ...

Issue with interactive rows in a table ( Rails Version 4 )

I am encountering an issue with a table that is linked to a customer show page _table.html.erb <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> <th width="50"><%= sort_link ...

React Leaflet causing a frequent map refresh due to context value updates

When I use map.on('moveend') to update the list of markers displayed in another component, I encounter a refreshing issue. The context in my project contains two arrays - one filtered array and one array with the markers. When I try to update the ...

The results do not appear when using Bootstrap 3 Typeahead

I am currently utilizing Bootstrap 3 Typeahead in conjunction with an ajax call. The function is successfully returning the data, however, it is not displaying. Below is my code snippet: $('#txtComune').typeahead({ minLength: 2, ...

What is the best way to extract a particular key value from a JSON object?

I am completely new to the world of APIs and just starting out with JavaScript. My goal is to retrieve the status of a server from a server hosting panel using an API. In order to achieve this, I need to log in by making a request to /API/Core/Login, extra ...