jQuery if statement problem
Hi everyone
I am working on my smart home project for college.
I am using jQuery to change value of the buttons however it doesn't work as desired
Whenever to floors are shown I would like to change the 3rd value (both floors) as well
Included code
- $(document).ready(function() {
- $("#groundfloor").click(function() {
- // changing attributes of the buttons
- if ($(this).text() == "Show ground floor") {
- $(this).text("Hide ground floor");
- }
- else if ($(this).text() == "Hide ground floor") {
- $(this).text("Show ground floor");
- }
- else {
- console.log("Error");
- }
- });
- $("#firstfloor").click(function() {
- // changing attributes of the buttons
- if ($(this).text() == "Show first floor") {
- $(this).text("Hide first floor");
- }
- else if ($(this).text() == "Hide first floor") {
- $(this).text("Show first floor");
- }
- else {
- console.log("Error");
- }
- });
- $("#bothfloor").click(function() {
- // changing attributes of the buttons
- if ($(this).text() == "Show both floors") {
- $(this).text("Hide both floors");
- $("#groundfloor").text("Hide ground floor");
- $("#firstfloor").text("Hide first floor");
- }
- else if ($(this).text() == "Hide both floors") {
- $(this).text("Show both floors");
- $("#groundfloor").text("Show ground floor");
- $("#firstfloor").text("Show first floor");
- }
- else {
- console.log("Error");
- }
- if (("#groundfloor".text() == "Hide ground floor") && ("#firstfloor".text() == "Hide first floor")) {
- $("#bothfloor").text = "Hide both floors";
- }
- else if (("#groundfloor".text() == "Show ground floor") && ("#firstfloor".text() == "Show first floor")) {
- $("#bothfloor").text = "Show both floors";
- }
- });
- });