Thursday 15 May 2014

javascript - How can I loop through an array of divs to show() them? -



javascript - How can I loop through an array of divs to show() them? -

first post.. experienced programming not much jquery/javascript. have divs hidden @ first, , assigned id's in ascending order:

<script> $(document).ready(function() { $(".over_map").each(function(i) { $(this).attr('id', "over_map" + (i + 1)); // console.log($(this)); }); }); </script>

now want loop through dynamic number of these divs , show them. if (eventually, not implemented yet) sql phone call returns 4 records, want show() 4 of hidden divs. seems should simple missing something.. limited net access unfortunately, didn't find stack overflow entries pertaining it.. help appreciated!

if have set of elements in jquery object, don't need loop them @ - phone call .show() on set.

e.g.

$('#over_map1, #over_map3').show();

if have list of ids want show, can build selector string:

function buildselector(ids) { var selectors = []; (var = 0; < ids.length; i++) { selectors.push("#over-map" + ids[i]); } homecoming selectors.join(", "); } $(document).ready(function(){ var ids = [1, 3]; $(buildselector(ids)).show(); });

demo @ http://codepen.io/precise54/pen/nkyzg

javascript jquery html show

No comments:

Post a Comment