Home > Back-end >  How can write JavaScript code without jQuery by using bootstrap 5?
How can write JavaScript code without jQuery by using bootstrap 5?

Time:09-22

Can I use this code for (bootstrap 5) without jQuery?

<script type="text/javascript">
 $( document ).ready(function() {
   setInterval(function(){
       var attend = jQuery('#pills-profile').hasClass('active');
       if(attend == true){
             jQuery('#id2').show();
             jQuery('#id1').hide();
         }else{
             jQuery('#id2').hide();
             jQuery('#id1').show();
         }
     }, 1000)
   });

CodePudding user response:

Something like this

document.addEventListener("DOMContentLoaded", function () {
  const first = document.getElementById("id1");
  const second = document.getElementById("id2");
  const attend = document.getElementById("pills-profile");
  setInterval(function () {
    if (attend.classList.contains("active")) {
      second.style.display = "block";
      first.style.display = "none";
    } else {
      second.style.display = "none";
      first.style.display = "block";
    }
  }, 1000);
});
  • Related