Yogesh Chauhan's Blog

How to create a flip pricing table using CSS and JavaScript?

in CSS & JavaScript on March 28, 2021

Most pricing tables are made of 3 columns so in this example, I have only included 3 columns. You can add more or less by adjusting HTML content by keeping the same class name.

Before you start here are some good reads to go through to understand the code completely. I have broken down the complete code in small sections in these 6 previous posts.

Let’s start by adding the HTML contents. We’ll add the onclick function flip() in radio buttons that will be fired on click. We’ll add the JavaScript for that at the end.

Now, let’s add the style for the table columns and flip.

Let’s add the toggle switch to give the users options of switching the table pricing – Monthly vs Yearly.

Since we have the content ready, all we need is a JavaScript code to fire the flip on user click.

We can use querySelectorAll to get all the columns with the class name “column”.

The code after that will be added to the function flip() we talked about earlier. The function will get fired onclick and the table flip will occur.

I also have a nice explanation on “How to check if radio button is checked or not using JavaScript?“, which was the most read article recently. I’ll use the same code to get the clicks and values.

Based on those values, we’ll add a class and remove a class which will create the flip effect.

Here’s the JavaScript code:

Here’s the working demo:


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 How to add Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface #Jan 14 How to display a student’s individual transcript in Colleague? #Jan 11 How to install PuTTY on a MacOS? #Jan 8 How to Install Xcode Command Line Tools on MacOS?
You might also like these
Function Scope in JavaScript for BeginnersJavaScriptbin2hex() and chr() String Functions in PHPPHPHow to check if the page is the home page in WordPress?WordPressSome SQL LIKE Operators We Need to Keep in MindSQL/MySQLOrder By and Group By in PostgresPostgresCan Firewall and IDPS Stop DDoS Attack?Miscellaneous