Ad

Using Array Variable And For Loop In Jquery

- 1 answer

$(document).ready(function(){
    var ar = ["#mob","#tv","#cmp","#prt"]; //div id's to display images
    $(".show").click(function(){
        for(var sh in ar){
            $(sh).css({"display":"block"});
        }
    },5000); 
});

i was trying to display images on button click with a delay of 5000, button on click event nothing is been happening.

Ad

Answer

The loop for in of javascript to far with PHP when you run for (var sh in arr) the sh will start from 0 to 3. That mean your code should be $(arr[sh]).css({"display": block});

Ad
source: stackoverflow.com
Ad