Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

296
Views
Javascript: how to function if class exists or change

Thank you, everyone! I am keep going design my game with Javascript.

There is box, id called 'box1'. Also, there is a hidden button. I have a function to change the box1 class.

I want to change the visibility if the box1 has the class "glow". In fact, I am planning to check 9 boxes class. Therefore, I may use && for "if" condition.

$(document).ready(function() {
  if (document.$('#box1').classList.contains('.glow')) {
    $(".btn-warning").css('visibility', 'visible');
}});
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

something like you can design your code

You have a 9 blocks with its like box1, box2, so on

Loops through get all class nodes

$("div[id^='box']").foreach(function(){
  if($(this).hasClass(".glow"))
  {
  // your logic
  $(".btn-warning").css('visibility', 'visible');
  }
}

I hope this will work for you

about 4 years ago · Santiago Trujillo Report

0

Thank you everyone for your comments. I change my logic.

I finish the code myself.

gameboxsize is the div for 9boxes.

setInterval(function() {
  var gamebox = document.getElementById('gameboxsize');
  var nodesSameClass = gamebox.getElementsByClassName('glow');
  console.log(nodesSameClass.length);
  var winNum = nodesSameClass.length;

  if (winNum === 9) {
    $(".btn-warning").css('visibility', 'visible');
  }
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!