JQuery - change css
How do I make an jquery - change css?
What is a jquery - change css? How do you make a jquery - change css? This script and codes were developed by Tyler Lesperance on 24 November 2022, Thursday.
JQuery - change css - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>jQuery - change css</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Click the box once to proceed</h1>
<div id="the-box" class="bad">The box</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
JQuery - change css - Script Codes CSS Codes
body { background: #D2D2D2;
}
h1 { margin: 1rem 0 1rem 3rem; text-transform: uppercase; font-family: 'Helvetica'; color: #292929;
}
div { width: 35rem; height: 8rem; line-height: 4; display: block; text-align: center; font-size: 2rem; color: #000; text-decoration: none; text-transform: uppercase; padding: 0.25rem; margin: 2rem auto; cursor: pointer; border: 2px solid #292929;
}
.good { background: #185901;
}
.bad { background: #980101; color: #FFF;
}
JQuery - change css - Script Codes JS Codes
// This time let's not only change the classes, but also change the css of the box with jQuery
$('#the-box').click(function () { // Using an if statement to check the class if ($(this).hasClass('bad')) { // The box that we clicked has a class of bad so let's remove it and add the good class $(this).removeClass('bad'); $(this).addClass('good'); // Let's also make this box a lot smaller $(this).css('width','10rem'); } else { // The user obviously can't follow instructions so let's alert them of what is supposed to happen next alert("You can proceed!"); }
});
Developer | Tyler Lesperance |
Username | tylerama |
Uploaded | November 24, 2022 |
Rating | 3 |
Size | 2,154 Kb |
Views | 42,504 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Vanilla JS - click event | 1,832 Kb |
JQuery - add and remove a class | 2,065 Kb |
Simple loading animation | 2,089 Kb |
My Favorite Hamburger | 1,893 Kb |
A Pen by Tyler Lesperance | 3,522 Kb |
Vanilla - DOM Loaded | 1,400 Kb |
JQuery - animate | 2,135 Kb |
FLIP animation inspired by Paul Lewis | 2,320 Kb |
JQuery - click event | 1,836 Kb |
JQuery - getting and setting href | 1,879 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
CSS3 iPad | Vikvarg | 1,766 Kb |
Custom Checkbox and radio inputs SCSS | Rgfx | 3,367 Kb |
The Fly | GianlucaGuarini | 3,405 Kb |
Bootstrap 4 Gridsystem Demo | Rivella50 | 1,535 Kb |
Button Option Group | Honchoman | 1,859 Kb |
Simple Responsive Text | Fbrz | 2,282 Kb |
CSS Tooltips | Darylldoyle | 2,599 Kb |
Arrow Navigation | Hinducows | 1,973 Kb |
Google Maps API Ground Overlay | Boycetrus | 2,961 Kb |
Buttons for autumn | Nikazawila | 1,795 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!