2021年5月7日星期五

Access array of div elements via jquery to .show() or .hide() each one individually for carousel

I'm creating a profiles page in javascript/jquery and I'm using a carousel of div's to accomplish said task. The question I have is, how do I programmatically access each style.display or $("#username").hide() or .show() ?

function changeProfile(num) {    var profiles = $('#profiles');    if (num < 1) {      index = 3;    }    if (num > 3) {      index = 1;    }    for (i = 0; i < 3; i++) {      profiles[i].style.display = "none"; // error here      // for example: $('#profiles')[0];  etc    }    profiles[index - 1].style.display = "block";    console.log("Profile number: " + index);  }
<div class="profiles">    1 / 3    <img src="images/blank1.jpg" style="width:90%">  </div>  <div class="profiles">    2 / 3    <img src="images/blank2.jpg" style="width:90%">  </div>  <div class="profiles">    3 / 3    <img src="images/blank.jpg" style="width:90%">  </div>
https://stackoverflow.com/questions/67444532/access-array-of-div-elements-via-jquery-to-show-or-hide-each-one-individua May 08, 2021 at 01:58PM

没有评论:

发表评论