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

Acquiring the applicable CSS for a JavaFX 8 widget

While working on JavaFX styling with CSS, I encountered a challenge in understanding which CSS properties are directly affecting the appearance of a GUI widget. It reminded me of using Firefox web developer tools to inspect elements and view the specific s ...

Is it possible to transfer items from one list within a component to another list inside a different component with Vue draggable?

I am having trouble implementing Vue Draggable to move items between lists within a component setup. The issue I'm facing is that the items can be moved within a list, but not from one list to another. The structure involves a Board component that ho ...

What is the approach of Angular 2 in managing attributes formatted in camelCase?

Recently, I've been dedicating my time to a personal project centered around web components. In this endeavor, I have been exploring the development of my own data binding library. Progress has been made in creating key functionalities akin to those f ...

The functionality of my Javascript code is restricted to a single element within a Python embedded for loop in Django2

My Python for loop is iterating through these HTML template cards, each accompanied by JavaScript. However, I'm encountering an issue where the JavaScript only seems to work on the first element (specifically, it's meant to retrieve the seeked po ...

Ways to reload a webpage from the bottom without any animation

It seems common knowledge that refreshing a webpage on mobile devices can be done by pulling down from the top. However, I am looking to shake things up and refresh the page by pulling up from the bottom instead. And I prefer no animations in the process. ...

Customizing Thickness for Tab Labels in MUI 5

I have been trying to adjust the thickness of the label inside a tab using MUI 5, but so far I haven't had success. Here is what I have attempted: interface TabPanelProps { children?: React.ReactNode; index: number; value: number; } funct ...

Inquiring about the intricacies of using Regular Expressions in

Can anyone provide a regex that only allows the characters 0-9, a-z, A-Z, hyphen, question mark, and "/" slash, with a character length between 5 to 15? I attempted the following approach, but it did not yield the desired result: var reg3 = /^([a-zA-Z0-9? ...

Using the `form` method with `get` works perfectly in Node.js, however, the status remains pending when checking in the developer tools

I am currently developing a website that utilizes forms for user voting. The goal is to submit these votes to a Mongo database using Node.js. However, I have encountered an issue where the code successfully updates the database but causes a stuck pending o ...

Getting pictures dynamically from the backend with unspecified file types

Greetings to my fellow Stackoverflow-Users, Lately, I was tasked with the requirement of loading images dynamically from the backend into my application. Up until now, it was always assumed that we would only be dealing with SVG images since there was no ...

The displayed value in the text field remains constant even when the object's attribute is modified

My issue involves the Date Text Field component of Material UI. Whenever I pass an attribute from an object, the displayed value in the Text Field does not update even when the object attribute changes. const [data, setData] = useState({ title: new Da ...

Error encountered: Multer does not recognize the field when attempting to upload multiple files in a node.js environment

I would like to upload two files in one request using Node.js and I am utilizing multer for this task. Here is my request in Postman: Additionally, I am using multer in routing: router.post( "/Create", UploadProfileHandler.single("sign ...

How come the Google fonts won't display correctly within my HTML document?

After importing some fonts into my CSS file, I noticed that they are not displaying correctly in the design. Below is the code for the imported fonts and CSS linking: https://i.stack.imgur.com/9RQ4u.png The output only shows sans-sarif working properly: ...

Attempting to alter the appearance of my validation control by implementing a custom style sheet theme

After naming a style sheet theme Basic and applying it to my web.config file, I created a Validator class in the css file. Utilizing the cssClass attribute with the Validator type, I successfully adjusted the font-weight property but struggled to change th ...

Sending serialized data via AJAX to a PHP controller using PDO

When a checkbox is checked or unchecked, an ajax call is triggered. As someone new to PDO MVC design, my goal is to pass serialized data to an object via the ajax call which then utilizes a function to store this data in the database. AJAX: $('#inte ...

Switch to using addresses instead of latitude and longitude coordinates when utilizing the Google Maps API

I am looking to utilize Google Map Markers to indicate the locations where our services are offered. The code I have created using latitude and longitude is functioning properly, however, for my project I need to display city names instead of lat/long ...

AngularJS does not recognize Model as a date object in the input

I am attempting to utilize AngularJS to showcase a date using an input tag with the type attribute set to date: <input ng-model="campaign.date_start" type="date"> Unfortunately, this approach is resulting in the following error message: Error: err ...

Mastering the art of exchanging cross-domain ajax data in userscripts

My current approach involves using this code to store and retrieve ajax data from $.ajax({ /* send data */ url: "http://api.openkeyval.org/store/", data: "test-key-data=" + JSON.stringify([123,456]), dataType: "jsonp", ...

Navigating with Express and Vue

Currently, I am working on a basic web page that has an index '/' and a 404 page to handle errors at '/404'. In my express app setup, I have the following configuration: // Entry Point app.use("/", express.static(resolve(__di ...

What is the process for generating and parsing an XML file using jQuery?

I've come across a lot of information on creating and sending XML files with Ajax, but I'm feeling pretty confused. My goal is to generate an XML file and send it to the server using Ajax. In return, I expect to receive another XML file. Below ...

Examining the words within strings and drawing comparisons

I am attempting to analyze words within strings for comparison purposes. This is my objective: var string1 = "Action, Adventure, Comedy"; var string2 = "Action Horror"; if (string1 contains a word from string 2 == true) { alert("found!"); } I have e ...