title: How to use Jquery Hide/Show with a foreach loop in PHP
body: <p>I want to have a read more section that expands without linking to another page so I am trying to implement the Jquery Show/Hide.</p>
  
  <p>The data to be expanded is coming from a foreach loop in php and I have created a function that adds the html markup if the content is long enough</p>
  
  <p>The problems that I am having is that if I click on one of the read more links, it expands all of them and it also scrolls to the top of the page away from where I need the browser to be.</p>
  
  <p>How do I make this work for only the link that is clicked.  Is there a way to add varibles from PHP to Jquery?</p>
  
  <p>The Jquery script in the HTML head</p>
  
  <pre><code>&lt;script src="js/jquery.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
  
  $('name#read').hide();  
  $('a#read_more').click(function(){
  $('name#read').slideDown('slow');               
  }); 
  $('a#read_less').click(function(){
  $('name#read').slideUp('slow');
  });
  });
   &lt;/script&gt;
  </code></pre>
  
  <p>The PHP function </p>
  
  <pre><code>function read_more($content){
  
  if (strlen($content) &lt; 150){
      return $content;
  } else {
      $content = substr($content,0,150) . "......&lt;a href='#' id='read_more'&gt;read more&lt;/a&gt;" . "&lt;a name id='read'&gt;" . substr($content,150) . "&lt;/a&gt;";
      return $content;
  }   
  
  }
  </code></pre>