title: How to get a value from div without write some event (onclick,etc) using jquery
body: <p>I have some question about how to get some value from some element like div,etc using jquery and without write onclick event or etc on the div where I want to get that value.  </p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="test" title="test1"&gt;test&lt;/div&gt;
      &lt;div id="test2" title="test2"&gt;test2&lt;/div&gt;
      &lt;script&gt;
          function getVal(attr,value){
              $("#show").text("this "+attr+" have value ="+value);
          }
          $(document).ready(function(){
              $("#test").click(function(){
                  getVal("#test",$("#test").attr("title"));
              }); 
          });
      &lt;/script&gt;
      &lt;div id="show"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Usually to get some value from div that i click, I add an onclick event on div like 
  <code>&lt;div id='test' onclick="getVal(test)" &gt;&lt;/div&gt;</code> 
  and it will return "test". And the code that I write above nearly what I want, but the problem that I have is if I have a many div, how can I get the value from each div that I click just using jquery click function and I don't need to write </p>
  
  <pre><code>$("#test").click(function(){
                      getVal("#test",$("#test").attr("title"));
                  }); 
  $("#test2").click(function(){
                      getVal("#test2",$("#test2").attr("title"));
                  });//and so on
  </code></pre>
  
  <p>here the code that I use to achieve what I want, using onclick event that I put on div:</p>
  
  <pre><code>    &lt;script type="text/javascript"&gt;
                  function overlay(rel){
                      var value = rel;
                      $(document).ready(function(){
                          $(".img"+value).click(function(){
                              $(".overlay-bg"+value).fadeIn();
                          });
                          $(".close"+value).click(function(){
                              $(".overlay-bg"+value).fadeOut();
                          })
                      });
                  }
              &lt;/script&gt;
          &lt;div id="gallery"&gt;
  
                                  &lt;img src="http://localhost/wedding/source/gallery/thumb/thumb-a.jpg" class="img1" onclick="overlay(1)" title="photo1" alt="photo1"/&gt; 
  
                              &lt;/div&gt;
  
                              &lt;div id="overlay-bg" class="overlay-bg1"&gt;
  
                                  &lt;div id="overlay"&gt;&lt;img src="http://localhost/wedding/source/gallery/a.jpg"/&gt;
  
                                      &lt;span&gt;photo1&lt;/span&gt;
  
                                      &lt;span style="font-size:0.8em;"&gt;&lt;p&gt;photo a&lt;/p&gt;&lt;/span&gt;
  
                                      &lt;div id="close" class="close1"&gt;&lt;/div&gt;
  
                                  &lt;/div&gt;
  
                              &lt;/div&gt;
  
  &lt;div id="gallery"&gt;
  
                                  &lt;img src="http://localhost/wedding/source/gallery/thumb/thumb-b.jpg" class="img2" onclick="overlay(2)" title="photo2" alt="photo2"/&gt; 
  
                              &lt;/div&gt;
  
                              &lt;div id="overlay-bg" class="overlay-bg2"&gt;
  
                                  &lt;div id="overlay"&gt;&lt;img src="http://localhost/wedding/source/gallery/b.jpg"/&gt;
  
                                      &lt;span&gt;photo2&lt;/span&gt;
  
                                      &lt;span style="font-size:0.8em;"&gt;&lt;p&gt;photo b&lt;/p&gt;&lt;/span&gt;
  
                                      &lt;div id="close" class="close2"&gt;&lt;/div&gt;
  
                                  &lt;/div&gt;
  
                              &lt;/div&gt;
  </code></pre>
  
  <p>I'm really want to know how to resolve my problem.</p>