OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Clicking on jQuery

  • Thread starter Thread starter soroush
  • Start date Start date
S

soroush

Guest
When I define a code to click and change that element again, I want the element to return to the first state with another click

I wrote another click but it didn't work The toggle didn't work properly either I want css to appear when clicked and css to be removed when clicked again


Code:
$("#green").click(function() {
  var audio = new Audio('sounds/green.mp3');
  audio.play();
  $("#green").css("background-color", "gray");
  $("#green").css("border", "20px solid white");
});

$("#green").click(function() {
  var audio = new Audio('sounds/green.mp3');
  audio.play();
  $("#green").css("background-color", "green");
  $("#green").css("border", "0px");
});

<p>When I define a code to click and change that element again, I want the element to return to the first state with another click</p>
<p>I wrote another click but it didn't work
The toggle didn't work properly either
I want css to appear when clicked and css to be removed when clicked again</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>$("#green").click(function() {
var audio = new Audio('sounds/green.mp3');
audio.play();
$("#green").css("background-color", "gray");
$("#green").css("border", "20px solid white");
});

$("#green").click(function() {
var audio = new Audio('sounds/green.mp3');
audio.play();
$("#green").css("background-color", "green");
$("#green").css("border", "0px");
});</code></pre>
</div>
</div>
</p>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top