Switch the visibility of an HTML input styled as a "spinner"

I have managed to create a CSS-based method for toggling the visibility of span or input elements depending on whether a radio button is checked. I got inspired by this insightful question on Stack Overflow.

However, I encountered an issue where this toggle effect stops working as soon as I apply a jQueryUI spinner format.

In this jsFiddle demo, you can see that the CSS works perfectly fine for the span element but not for the input. In fact, applying the spinner causes the entire input to disappear.

Can anyone shed some light on why this is happening and offer insights on how to maintain the visibility toggle using CSS?

Below is the CSS code snippet used in the fiddle:

    /* Control visibility of SPAN and INPUT (with jqueryui spinner class)
cf. https://stackoverflow.com/questions/21269376/radio-button-show-hide-content
*/

/*The span works fine*/
span#some-text {
    display:none;
}
input#on-input:checked ~ span#some-text{
  display:inline;
}
input#systematic-input:checked ~ span#some-text{
  display:none;
}

/*The input is only visible when the spinner format isn't applied (i.e. commenting all CSS below this point). Even so, the hide/show effect doesn't work. Why?*/

/*
input#spinner-on {
    display:none;
}
input#on-input:checked ~ input#spinner-on{
  display:inline;
}
input#off-input:checked ~ input#spinner-on{
  display:none;
}
*/

Answer №1

When using jQueryUI spinner, the input is enclosed within a span element.

To customize the appearance of the spinner input, you can wrap it in a new span and adjust the CSS accordingly.

span#spinnerWrapper {
    display: none;
}
input#on-input:checked ~ span#spinnerWrapper {
    display: inline;
}
input#off-input:checked ~ span#spinnerWrapper {
    display: none;
}

You can view an example on this jsFiddle:

http://jsfiddle.net/scc0jyns/2/

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

Expansive Child Division with Ample Margins

I'm currently working with a nested set of divs and I need the inner div to occupy the full width without extending beyond the parent div's margins. Despite trying to use max-width:100%, it hasn't been successful so far. For this particular ...

A way to update a PHP code using AJAX without automatically fetching an external file

Recently, I managed to create a PHP page that pulls data from a table in a database and then utilized an HTML page to retrieve the PHP file and refresh it using AJAX. However, my goal now is to embed the PHP code directly into the HTML file and refresh tha ...

Responsiveness of a div containing various content

I am currently working with Bootstrap 4 and my HTML code looks like this: <div class="font-weight-bold col-12"> <span>Filter :</span> <input type="text" class="form-control" /> </div> Initial ...

Reposition and resize an image. Creating a grid layout

I'm having trouble with positioning and cropping an image correctly on my website. I want it to look like this (hero-section): The entire project is based on a grid layout. I need a circular image that is larger than the container, positioned to the ...

The behavior of Material-UI Drawer varies when used on tablets

Encountering some strange issues with the Material-UI drawer component. It's scrolling horizontally on my iPad, while it scrolls vertically on my MacBook and Android Phone. Expected Result on MacBook: https://i.sstatic.net/txBDf.png On my MacBook, it ...

Assistance needed with CSS floating properties

Despite seeing many inquiries about float, I still can't pinpoint what's causing my issue. My objective is simple: GREETINGS FRIEND I aim for it to align just to the left of the unordered list. Referencing this solution, I attempted adding cl ...

In my current Next.js project, I tried setting up a new [collectionId].jsx file within the pages directory, but I am facing issues with getting

In my current next.js project, I recently created a file named [collectionId].jsx within the pages directory. Interestingly, I noticed that Tailwind CSS does not seem to work properly with this file. However, when I renamed the file to [collectionId].js wi ...

Move the items downwards to occupy any empty space vertically

Just a quick overview of the code I'm working with (I am using Material UI in React). This container is meant to hold chat messages exclusively. const ChatContainer = ({ chatMessages }) => { const classes = useStyles(); return ( <Paper ...

Tips for extracting text from a specific div using jQuery

Hey there, thanks for taking the time to read this message. I have some HTML code below: <div id="ImagePagination" class="Pagination"> Photo <span id="currentPhotoCount"><#currentPhotoCount#> </span> of <span i ...

Internet Explorer failing to trigger Ajax requests

I'm encountering an issue with my script on my webpage - it works perfectly in Chrome, but Internet Explorer is not entering the success{} function of Ajax. It does go into the Complete{} function without any problems. I attempted to pass the data var ...

Submitting forms that contain files using jQuery and AJAX

Despite searching through numerous questions on this topic, I have yet to find a solution to my specific issue. My objective is to successfully submit an entire form, potentially containing files as well. The code I currently have is not working: $(target ...

How to customize the hover background color for multicolored series in Highcharts?

Highcharts offers a background color for all columns in a series. The hover color across themes is consistently a light blue (155, 200, 255, .2). To see an example, visit: http://jsfiddle.net/38pvL4cb/ If you look at the source code, Highcharts creates a ...

Retrieving the checkbox's status from the database

I have implemented a basic checkbox that updates its state in the database when clicked or unclicked. Is there a way to retain this state and have it displayed as checked if the page is refreshed? Essentially, I want the checkbox to remember its last state ...

Utilizing a jQuery AJAX call to fetch information and loop through the results

Implementing jQuery var seconds = 6; var timeout = seconds * 1000; function callAPI() { $.ajax ({ url: "getdata.php", dataType: "json" }).done(function(data) { console.log(data); // Stuck on handling returned jso ...

Navigate to the initial visible element on the specified webpage via the page hash link

In my handlebars HTML template, I have a partial view that includes different pieces of content for desktop and mobile. I use different CSS classes to hide and show these elements accordingly. <div class='hideOnMobile showOnDesktop'> < ...

The progress bar is visually enhanced with a border style that doubles as a background color

While experimenting with a jsfiddle to create an animated progress bar, I stumbled upon something peculiar. I had a single CSS rule applied to the progress tag: progress { border:2px solid #ccc; } Prior to adding this CSS rule, the progress bar looke ...

Is there a method to consistently keep the horizontal scrollbar in view for the MUI Data Grid at all times?

I have a Data table with virtualized columns, totaling more than 25 in number. Users can easily scroll horizontally using a trackpad, but without one, they may struggle to access all the columns due to the delayed appearance of the scrollbar. Is there a w ...

Animating splitting elements with VueJS

I am facing a challenge in creating a split animation with two icons. My goal is to split the icons with some translation in the X-axis after hovering on the container, but it seems like I am missing something in my implementation. The animation does not w ...

Tips for displaying the attributes of a product when making edits within a modal utilizing jquery, ajax, and Laravel

Struggling to update product details through a modal populated with inputs, including dropdowns and radio buttons. Using jQuery AJAX for data retrieval from the table. // show editing modal $('body').on('click','#editrentalhsedeta ...

Adding events to a TinyMCE iframe in WordPress

Recently, I implemented some customized div wrapper styles in Wordpress. However, when utilizing these styles on a page, I encountered difficulties adding content below them. Despite using CSS:after within the divs to generate a selectable area, this metho ...