Display a switch icon based on input created by the user

I've been struggling to implement a toggle button for user-generated input, specifically using a Font Awesome toggle button.

Here is the link to my codepen: http://codepen.io/lucky500/pen/bdpzbd along with the code snippet:


<div id="list" class="greatList clearfix">
    <ul class="greatList" style='display: none;'>
        <li class="items">
            <div class="box">
                <i class="fa fa-toggle-on fa-2x active" id="on"></i>
                <i class="fa fa-toggle-on fa-2x fa-rotate-180 inactive" id="off" style='display: none;'></i>
            </div>
        </li>
    </ul>   
</div>

Jquery


$(document).ready(function(){

    // Toggler
    $('.box').click(function() {
        $('.inactive, .active').toggle();
    });

    var trash = '<span class="delete">X</span>';
    var toggleButton = '<div class="box"></div>';

    // Allow user to submit using Enter key
    $('#addButton').click(function(e){
    e.preventDefault();
    var item = $('#addItems').val();
    var placeIt = $('<li style="display: block;">' + toggleButton + item +  trash + '</li>');

    if(!$.trim($('#addItems').val())) {
        alert('Please enter text to add to the list');
    } else {
        $('.greatList').append(placeIt);
    };
    })

    // Remove li when .trash is clicked
    $(document).on('click', '.delete', function() {
    $(this).closest('li').fadeOut(350);
    });

});

Any assistance would be greatly appreciated!

Answer №1

After some tinkering, I found that adding the i tag within my toggleButton variable did the trick. Now, it's time to make sure my toggle actually functions as intended!

var toggleButton = '<div class="box" style="display: block;"><i class="fa fa-toggle-on fa-2x active" id="on"></i></div>';

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

Getting the Firebase Project Name or ID from a Cloud Function is a simple task that involves using

While working with Cloud Functions, I need to retrieve the project name from one of my Javascript server files. The project name is stored in .firebaserc file, but I am not sure if this file is accessible on the server side. Is there a way to achieve somet ...

Prevent those pesky popups with this handy script

Even though AdBlock sometimes doesn't block popups, I have a solution in mind. I plan to use Greasemonkey and jQuery to create my own popup blocker. Is it possible to intercept the clicks and determine if a popup is about to open? $('.popupLaun ...

The extended class possesses a distinct type from the base class, which is reinforced by an interface

Is it possible to write a method that is an extension of a base class, but with a different return type, if supported by the shared interface, without adding a type declaration in class 'a'? In practical terms, classes a & b exist in JavaScript ...

Guide on invoking an Angular 1.5 component with a button press

Having just started learning Typescript, I'm struggling to figure out how to call my Angular component "summaryReport" on a button click. Here's a snippet of my code: Let's say I have a button that should call my component when clicked with ...

The scraping tool from Snipcart encountered issues while trying to capture product data in a Next.js

I am encountering an issue with Snipcart while using it in a Next.js app integrated with Strapi. The error message I receive when processing a payment is as follows: A 'cart-confirmation' error occurred in Snipcart. Reason: 'product-craw ...

overlapping text placed directly above another text

Is there a way to place a text fragment above another part of the same line? <div>Th<div class="ac">Am</div>is is an ex<div class="ac">E</div>ample line</div> If implemented, it should display as: Am E This ...

dynamically open ngx-bootstrap accordion panels

I implemented the ngx-bootstrap accordion feature to display a list of blog posts. Below is the template structure: <accordion id="blog-list"> <accordion-group *ngFor="let post of posts; let first = first;" [isOpen]="first" id="post-{{post.i ...

Issue with Vue class binding failing to update when state is modified

I'm attempting to utilize Vue class binding depending on the index within the v-for loop. While I can see that the state in Vue dev tools is changing correctly, the class name itself isn't being updated. <div class="group" v-for= ...

Using npm: Managing Redirects

Does anyone have suggestions on how to manage redirects using the Request npm from websites like bitly, tribal, or Twitter's t.co URLs? For instance, if I need to access a webpage for scraping purposes and the link provided is a shortened URL that wil ...

Struggling with CSS Flexbox when it comes to organizing rows and combining Table and Table Cells

I've been struggling to fix a CSS flex problem for hours. My goal is to make sure that the three boxes in each row have the same height. While I'm familiar with using flex, I suspect that floats may be the root of the issue. Even after clearing t ...

What is the method for adding an attribute without a value to an HtmlGenericControl in C#

In my C#/ASP.net project, I am creating a new HtmlGenericControl and I need to add an attribute to the control without assigning it a value. This means having no ="" after the attribute name. oHtmlGenericControl = new HtmlGenericControl("MyHtmlTag"); oHtm ...

The upper margin is ineffective

Apologies, I am new to CSS. Here is the HTML code I have: <div class="box-A" >Box A content goes here</div> <div class="box-B" >Box B content goes here</div> I attempted to apply the following CSS to it: .box-A{ background-c ...

Vue.JS enables the seamless addition of rows to a form on the fly

I am currently working on creating a dynamic form using Vue. The concept is that when the user clicks the add button, another row will appear for them to input data. However, I encountered an issue where initially only 1 row was set up, but when I added th ...

Convert radio input and label into a clickable URL text

Apologies for my lack of experience. I am simply trying to wrap my head around something. <span class="button"> <input type="radio" id="button-2" name="button-group-1"> <label onclick="changeButton('2');" f ...

Prevent rendering a file in node.js using ejs if it cannot be found

I have a specific folder structure under the views directory, containing an EJS file named profile_60113.ejs views docs profile_60113.ejs To dynamically render the file based on the groupID (where data.groupID == 60113), I use the following c ...

Maximizing the potential of .delegate in combination with .closest

$('.inputRadio').parent().click(function (e) { //implement delegate method here }); Looking for assistance on how to integrate the delegate method in the provided function. Any suggestions? ...

How to ensure a centered page layout in IE7 when zoomed in

I'm currently working on a website for a client who has requested that their page zoom perfectly in IE7. I've managed to address most of the bugs, but there is still one issue remaining. When the page is zoomed in, it centers properly, but upon ...

How can I conceal the source code of my website on Joomla 1.5?

Is there a way to protect my website's source code from being accessed by users? For example, preventing right-clicks on the page like this: If hiding the entire source code is not possible, is there a way to conceal specific parts of it? Specificall ...

What is the process for mediating a SWF-Flash file with a PHP mediating, also known as an HTTP-Pseudostreaming script?

I am currently developing a mini context media platform that utilizes HTTP Pseudostreaming. This involves using a PHP script to manage the media file, ensuring proper access and linking to the correct directory. Below are the key components of my code: // ...

In my React application, I have integrated p5 sketches that constantly loop and repeat

Currently facing a challenge integrating p5 sketches into my React App. I've tried adjusting the z Index of the toolbar to place the p5 elements underneath, but they end up repeating instead. Check out the repository here (sketches can be found in the ...