Is there a way to remove the highlight from a non-active block?

Hey friends, I need some help with my code. Currently, when I click on a table it gets highlighted, and if I click on another table, the previous one remains highlighted along with the new one I clicked on. How can I modify the code so that when I click on a new table, the previous one gets unhighlighted?

$('.pricing-customer').on('click', function(){
  $(this).toggleClass('active');
  $(this).children().toggleClass('active');
});
.pricing-customer {
  background: #fff;
  min-height: 250px;
  cursor: pointer;
  transition: all .3s ease-in-out;
  margin-bottom: 20px;
  padding: 10px 0px 25px 0px;
}
p.pricing-number {
  font-size: 52px;
  margin-bottom: 10px;
  margin-top: 20px;
  color: #fead0d;
}
p.pricing-monthes {
  color: #5e6977;
  font-size: 14px;
  line-height: 21px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e1e8ee;
}
p.emails {
  color: #444;
  font-size: 16px;
  line-height: 21px;
}
.pricing-customer:hover, .pricing-customer.active {

 background-color: #333;
}
.pricing-customer:hover p , .pricing-customer p.active{
  color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pricing-customer col-sm-12 col-sm-3 text-center">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</div>

Answer №1

Try using the siblings method instead of children. I believe this is what you are searching for.

$('.pricing-customer').on('click', function(){
  $(this).toggleClass('active');
  $(this).siblings().removeClass('active');
});
.pricing-customer {
  background: #fff;
  min-height: 250px;
  cursor: pointer;
  transition: all .3s ease-in-out;
  margin-bottom: 20px;
  padding: 10px 0px 25px 0px;
}
p.pricing-number {
  font-size: 52px;
  margin-bottom: 10px;
  margin-top: 20px;
  color: #fead0d;
}
p.pricing-monthes {
  color: #5e6977;
  font-size: 14px;
  line-height: 21px;
  padding-bottom: 20px;
  border-bottom: 1px solid #e1e8ee;
}
p.emails {
  color: #444;
  font-size: 16px;
  line-height: 21px;
}
.pricing-customer:hover, .pricing-customer.active {

 background-color: #333;
}
.pricing-customer:hover p , .pricing-customer.active p{
  color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pricing-customer col-sm-12 col-sm-3 text-center">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</div>

<div class="pricing-customer col-sm-12 col-sm-3 text-center">
  <h3><?php echo $t_title; ?></h3>
  <p class="pricing-number">$ 70</p>
  <br>
  <p class="pricing-monthes">per week/month</p>
  <p class="pricing-emails">100 000 emails</p>
</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

Having trouble displaying the time in the middle square when pressing TouchableOpacity in React Native?

Having trouble pressing the TouchableOpacity button as it's not responding, and even after pressing it, I need to access the time picker to select a specific time to display inside the square view in the center. Any suggestions on how to resolve this ...

Is there a method in VBA to access elements generated by javascript code?

After spending several hours conducting thorough research on Google (including browsing StackOverflow), I've been trying to find a method that would allow me to target HTML elements generated by JavaScript in VBA. For instance, using ie.Document.getE ...

Error in designing the ReactJS navbar (utilizing internal Bootstrap CSS)

I am facing an issue with the navigation bar in my project. When I use a link to an external source for the navigation bar, it works fine. However, when the internet connection is slow, I notice a brief loading time for the navigation bar which is quite bo ...

Why is my Vue list not showing the key values from a JavaScript object?

I am struggling to utilize a v-for directive in Vue.js to display the keys of a JavaScript object in a list. Initially, the object is empty but keys and values are populated based on an API call. Here's an example of the data structure (I used JSON.st ...

Creating parallel lines utilizing pseudo elements

Can someone assist me in drawing double lines under my paragraph using pseudo elements only without using display block? Here is my code snippet with display block: p:after { content: ""; display: block; width: 40px; margin: 20px auto 0; bord ...

Responsive Image Resizing with Bootstrap for Smaller Screens

I'm struggling to resize a responsive image in Bootstrap using the carousel example on their official website. <div class="container"> <div class="other-div"> .... </div> <div id="carouselExampleCon ...

Dealing with Mouse-Operated Data Deletion in a TextBox

I have a unique requirement that involves displaying a button labeled Set only when the text in two separate Text input fields matches. If the text in both fields matches, I am successfully able to control the visibility of the Set Button. However, I enc ...

Next.js is throwing an unhandled runtime error of type TypeError, which is causing issues with reading properties of null, specifically the 'default' property

"use client" import { useKindeBrowserClient } from '@kinde-oss/kinde-auth-nextjs' import Image from 'next/image'; import React from 'react' function DashboardHeader() { const {user} = useKindeBrowserClient(); r ...

Writing and altering content within the <code> element in Chrome is unreliable

Utilizing a WYSIWYG Editor with contenteditable functionality allows users to input "code snippets" using a <code> element. Here is an example: <div contenteditable="true"> <p> This is a paragraph with an <code>inline s ...

Making the toggle button functional on the navbar

Trying to customize my navbar for tablet and mobile devices is proving to be a challenge. I am looking for a way to make the dropdown button take up the entire page when clicked on. It seems like JavaScript might be the solution, but I'm not quite sur ...

Positioning a dropdown menu on top of a Google Map in React with JavaScript: Best Practices

I've been attempting to place a dropdown menu at a specific location on my Google Map, specifically in the top right (or top left is also acceptable). Below is the current output I am seeing: Here is the expected result: Modifications After trying ...

Associate the URL with the object to retrieve the corresponding object

https://i.sstatic.net/cj5N4.png When iterating through this array, I currently loop through it in the following manner: {props.choosenMovie.characters.map((characters) => ( <p>{characters}</p> /* This displays the URL of course */ ))} ...

Troubleshooting Problem with Retrieving Files Using jQuery Ajax

I am attempting to use ajax to retrieve the contents of a file, but it doesn't seem to be functioning properly. I'm not sure why this is happening, as I have copied the same code from the examples on w3schools.com. $().ready(function(){ ...

Unlocking the potential of the Bootstrap search dropdown

Currently, I am utilizing the following code to create a searchable dropdown menu. I found helpful guidance in this forum post. I am seeking advice on how to retrieve the value of the selected option. For example, if 'China' is chosen, I would l ...

Having difficulty with pagination within a callback function

I have been attempting to paginate in a call to a callback function, but I am encountering an error on the second call. Here is what my function does: let content = '' let size = 100 let from = 1 function result(size, from, callback) { ap ...

Is it possible to utilize both the /app and /pages folders in my Next 13 application?

I am currently working on a project where the /app folder is utilized as the primary route container. However, we have encountered performance issues on localhost caused by memory leaks identified in an issue on the Next.js repository. I am curious to fi ...

Django: Directing users to the login page upon clicking the star icon for favorites

I'm currently in the process of developing a media server that will feature a small star icon next to each video. By implementing a JQuery event handler, whenever the user clicks on the star button, an AJAX POST request will be sent to the server&apos ...

Tips for positioning a highcharts pie chart and legend in the middle of a page

I'm struggling to center my highchart data in a node/react single page application. Currently, it appears off-center like this: https://i.stack.imgur.com/ccR6N.png The chart is floating to the left and I would like to have everything centered within ...

Adjust the size and color of text in Chart.js using Angular 5

Why does the font color in chartjs appear as light gray and not print when you want to do so from the page? I tried changing the font color of chartjs in the options attribute, but it didn't work. How can I change the font color in chartjs angular? ...

Iframe Interactivity

My goal is to create an interactive iframe that will match the current parent URL (). For example, if I have an iframe pointing to http://www.google.com and click a link within the iframe, it should update the parent URL to , and then load the clicked con ...