Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a button that when is on click it takes some styles with JavaScript.

but i want to disable this style with second click.

how i can do this?

What I have tried:

HTML
<button class="class 1">FOR Test</button>

JavaScript
$(".class 1").click(function () {

$(".class 1").css("font-weight", "700");

});
Posted
Updated 26-Feb-19 1:49am
Comments
W Balboos, GHB 26-Feb-19 9:37am    
Your code is NOT javascript. Maybe jquery? You should make it your business to know what you're using - the answer depends upon it.

1 solution

The selector .class 1 actually looks for an element 1 inside an element with class as class. And class="class 1" actually sets two classes on the element: class and 1. That's not what you intend, so use class="class_1" (or anything without spaces) and $(".class_1").

And to disable the styles afterwards, instead of using .css I'd create a CSS class with your style, and use toggleClass[^] inside the click handler.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900