javascript - JS: Check for parameter in URL then iterate a function with parameter as var -



i've following piece of code:

<div id="1" class="hide"> text1 </div> <div id="2" class="hide"> text2 </div> <div id="3" class="hide"> text3 </div> <div id="4" class="hide"> text4 </div> <div id="5" class="hide"> text5 </div> 

want divs hidden function check:
-if url contains parameter equal id of 1 of div
-do this, each of div: check if url contains parameter 1 5.
-hide elements except 1 id matching parameter. 1 parameter in url @ same time.

function code, separate function can called other links:

function showone(id) { $('.hide').not('#' + id).hide(); } 


here iteration loop, not sure how piece them in specific way need directions appreciated.

 while (i<6) {     if (window.location.search.indexof('i=yes') > -1)     {     showone(i)     }}  

you not iterating i , checking string "i=yes" not "1=yes"

while (i<6) {       if (window.location.search.indexof(i + '=yes') > -1)     {         showone(i);         break;     }     i++; }  

Popular posts from this blog