Toggle jQuery to hide a div and update its CSS styling

There is an anchor with the class of "hide-btn1" that I want to trigger a series of actions when clicked:

  1. The rcol-content should hide and the text should change from Hide to Show
  2. The #container width needs to increase to 2038px
  3. The table.status-table width must be increased to 1669px

I've written this code snippet so far, but I'm not sure how to proceed:

$('.hide-btn1').on('click', function(e) {
     e.preventDefault();
     $(this).text(function(i,v) {
           return v === 'Show' ? 'Hide' : 'Show';
     });
});

Note: I have also included the requested HTML Code below:

<div id="container">
   <a class="hide-btn1">Hide</a>

   <div class="rcol-content">
        <p>This would be included in the right column</p>

   </div>
   <table class="status-table>
     <tr>
       <th>Heading</th>
     </tr>
     <tr>
        <td>Table Data</td>
     </tr>
   </table>

</div><!-- end container -->

Answer №1

I have implemented a solution based on the information you provided. A quick way to achieve this is:

$('a.hide-btn1').click(function(){
    $('.rcol-content').toggle();
    $('#container').css('width','2038px');
    $('table.status-table').css('width','1669px');
});

However, I would suggest adding a class with CSS below the default styles in the stylesheet instead of using JavaScript to generate CSS.

$('a.hide-btn1').click(function(){
    $('.rcol-content').toggle();
    $('#container').addClass('newClassOne');
    $('table.status-table').addClass('newClassTwo');
});

I hope this solution is helpful. As others have mentioned, it would be beneficial to provide a fiddle or codepen to further explain your desired outcome. Good luck!

Fiddle here

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

Unable to refresh HTML table using Vuex data in Vue JS

I am new to working with Vue.js and particularly Nuxt. I am facing an issue with updating a table using data fetched from the backend. Even though I can see the data in the Vuex tab when the page loads, I cannot seem to populate the table with it. The func ...

Preserve marked checkboxes upon page refresh

So I created a search engine with a filter using checkboxes in a form. The filter function is working fine when I submit the form (I'm using Flask for this). However, once the results are displayed, the checkboxes that were used as filters become unch ...

Comparing Two Arrays in AngularJS and Disabling on Identical Cases

I currently have two tables: "Available subject" and "Added subject" which are populated by ng-repeat with two separate lists of objects. My objective is to accomplish three things: 1 - When the user clicks on the plus sign, a row with identical content s ...

"I'm experiencing an issue in Laravel where the Ion range slider's color and dragger are

I'm currently implementing ion-rangeslider into my project. Here is the HTML code I've used: <div style="position: relative; padding: 200px;"> <div> <input type="text" id="range" value="" name= ...

Can the ThreeJS element be seen?

I am facing a challenge in my ThreeJS application where the view automatically centers on an object if it is close to the center of the view and closer than a specified distance. While I have information about the latitude and longitude of all objects and ...

Is it possible to exclude certain static files from being served in express.static?

const express = require('express'); const app = express(); app.use('/app', express.static(path.resolve(__dirname, './app'), { maxage: '600s' })) app.listen(9292, function(err){ if (err) console.log(err); ...

Tips for setting a default value from JSON using jQuery

After reviewing the link about setting radio button 'checked' in jQuery based on ID, I found it wasn't quite suitable for my needs. Here is my code: <label for="basic" class="basic">Gender:</label> <fieldset data-type="horizo ...

Is passportjs responsible for managing user registration?

Is it possible to utilize Passport for user signup if I am storing user information on a self-hosted server and cannot find a user signup function in the Passport.js documentation? ...

jQuery AJAX request only successful after page refresh

I had previously asked a question similar to this one and received a working solution. However, as I continued with my beginner project and delved into AJAX, I encountered a new issue. It seems that the AJAX call is not successful until the page is reloade ...

Transforming an Ionic mobile application into a web-based application: A step-by

I currently have a mobile app developed using Ionic. I now require a desktop-friendly website version of the app to cater to users who wish to access it from their computers. Can anyone point me to any resources or documentation that demonstrate that th ...

Steps for exporting various elements from a .vue file

In my Vue project, I am incorporating TypeScript along with Vue. There is a specific scenario where I need to export multiple items from my .vue file. Here's an example of what I want to achieve: // FooBar.vue <template> ... </template& ...

Using `texture.needsUpdate = true` in Three.js can cause significant performance issues due to its slow execution

I am currently working on a project involving a Three.js scene where I need to update textures after a certain period of time. However, I have noticed that updating the textures is causing a significant slowdown in the FPS, dropping it to 1-2 FPS for sever ...

Tips for detecting when no checkboxes in a group are selected or when at least one checkbox is selected, and then applying a class to the corresponding div

<div class="accordion-group"> <div class="accordion-heading"> <a href="#collapse" data-parent="#accordionQuiz" data-toggle="collapse1.." class="accordion-toggle"> <strong>1...</strong> Question ...

SleekScroll, SafariAssist, and Adaptive Navigation

I have a few queries regarding this side here Is there a way to implement smooth scrolling? I've experimented with different options, but removing the .slim from jquery breaks the dropdown functionality. How can I resolve this issue? I encounter ...

What's the best way to ensure that only the most recent 100 entries are retained in a CSV file

Currently, I am working on an application that requires me to extract timestamp-based parameter values from various devices. The data is highly structured and because I have to retrieve 100k rows every few minutes, I haven't explored the option of usi ...

Sequencing the loading of resources in AngularJS one after the other by utilizing promises

While working in a service, my goal is to load a resource using $http, store it in a variable, load a child resource and store that as well. I understand the concept of promises for this task, but I am struggling with how to properly implement it in my cod ...

I'm having trouble with getting my Bootstrap CSS and JS links to function properly

The paths for the Bootstrap CSS and JS files have been included in the code, but unfortunately, they are not working. Instead, I am getting the following errors in the console: GET http://127.0.0.1:5000/[https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist ...

Utilizing Cookies in an AJAX Request for Cross-Domain Communication with Pure Javascript

I am in the process of developing an Analytics application and I'm seeking a method to uniquely identify each user's device. Currently, my approach involves generating a "cookie" from the server side to track all page clicks and interactions thro ...

Vue JS ensures that it has all the necessary data before proceeding with the

I've been grappling with a VueJS data rendering issue for a few weeks now. My approach involves making axios calls, some nested within others. The problem I'm facing is that the data renders before the calls have completed, resulting in an empty ...

Issue with by.cssContainingText function not performing as intended

I have a container that I want to be able to click on. Here's how it looks: <div class="CG-Item CG-B-Left ng-binding" ng-bind="SPL.showTitleText">My New SPL</div> So I am trying to use this code to click on it: element(by.cssContainingT ...