Michael Grigsby
Michael Grigsby

Reputation: 12163

jQuery/Js looping over Codeigniter MySQL outputted data

$("#areaCodeList").click(function() {
   //onClick slideDown hidden church lists
});

in Javascript or jQuery how would I loop over multiple outputted database entries? What I need it to do is be able to uniquely identify the different rows and be able to act on each one rather than acting on all. I need the jQuery or Javascript to act like a Php while loop. Does this make sense to anyone?

<div class="areaCodeList" id="areaCodeList"><?=$row->areacode." - ".$row->locational_state;?></br></div>

Upvotes: 2

Views: 224

Answers (2)

Downpour046
Downpour046

Reputation: 1671

UPDATE 12:45PM : Change of entire page:

http://jsfiddle.net/eEtja/ - I created this fiddle with one panel. I rewrote the code on the page. Now that I better understand your PHP after looking it give this a shot. I did not modify your PHP.

I updated the JavaScript to reflect the following: (please make sure .churchList is still a class)

$(document).on("click", ".areaCodeList", function(){
            $('.churchList').hide();
            $(this).next('.churchList').show();
 });

Upvotes: 1

Rory McCrossan
Rory McCrossan

Reputation: 337570

Use each() to iterate over a group of DOM elements:

$(".areaCodeList").each(function() {
    var $this = $(this);
    // Your code here to act on each individual element.
});

More info on each()

Upvotes: 2

Related Questions