i have 2 divs inside foreach loop .first div has information about a company but shortened form and in second div has full form of information about a company . i want to hide first div and show second div when ‘show more ‘ link of that company has clicked .in my code when i click ‘show more ‘ link and it shows all company not only the company which i clicked .
<?php
$X = 0;
foreach($companyRows as $row){ ?>
<div class="first" >
echo "a company information shortend form"
</div>
<div class="second" style="display:none">
echo "a company information full form"
</div>
<a class="show_details"> show more</a>
<?php $X++;
} ?>
and here is jQuery . i am new in jquery and php.
<script type="text/javascript">
$(document).ready(function(){
$(".show_details").click(function(){
$(".second").show();
$(".first").hide();
});
});
</script>
and want to change show more link to show less.
add a parent
<div>in your loop… so that all this html stay inside a parent div.. this way we can use parent()..JQUERY
*UPDATED*
html().. to replace the text inside the clicked link or u can use text()