title: How to get all the links of a list inside a div?
body: <p>I have a code with the following DOM Tree:</p>
  <pre><code>&lt;div id=&quot;blogPagination&quot;&gt;
      &lt;div class=&quot;pagination&quot;&gt;
          &lt;ul&gt;
              &lt;li&gt;
                  &lt;a href=&quot;/2&quot; &gt;1&lt;/a&gt;
              &lt;/li&gt;
              &lt;li&gt;
                  &lt;a href=&quot;/3&quot; &gt;2&lt;/a&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>I'm trying to reach the href of my  tag. I can't reach it with anything I tried.</p>
  <p>What's the best way to reach it with jQuery ?</p>
  <p>I tried:</p>
  <blockquote>
  <p><code>console.log($('#blogPagination div ul &gt; li a ').attr(&quot;href&quot;));</code></p>
  <p><code>console.log($('#blogPagination &gt; a ').attr(&quot;href&quot;));</code></p>
  <p><code>$('#blogPagination').children('a') </code></p>
  <p><code>console.log($('#blogPagination div ul li a').attr(&quot;href&quot;));</code></p>
  </blockquote>
  <p>without luck ..</p>
  <p>Thanks</p>
  <p>EDIT:</p>
  <p>After nbrooks's answer, here is what I tried so far:</p>
  <pre><code>function bindPagination() {
      
      console.log(&quot;bind&quot;);
  
      $(function() {
          var links = $(&quot;#blogPagination ul a&quot;).map(function(e) {
          e.preventDefault();
              return this.href;
          }).get();
          console.log(links);
  });
  </code></pre>
  <p>EDIT 2 :</p>
  <p>Considering Syfaro's answer, I've also tried :</p>
  <pre><code>$('#blogPagination').find('a').each(function(e) {
      e.preventDefault();
      console.log($(this).attr('href'));
  });
  </code></pre>
  <p>Without luck.</p>
  <p>EDIT 3 :
  I'd like to give more details concerning this function that may have a significant impact after all:</p>
  <p>to load this pagination, I'm using Ajax and handlebars wrapped into a document ready function:</p>
  <pre><code>$(document).ready(function(){
      
      // Get the customer service stats
      var Content = {
  
      init: function() {
  
              /* this.getHomePosts(); */
              this.getBlogPosts();
          },
  
      getBlogPosts: function(offset) {
          if(offset == undefined){
              offset = 0;
          }
          // GET the events with JSON
          $.ajax({
              type: &quot;POST&quot;,
              data: {},
              url: site_url+&quot;/main/blog/&quot;+offset,
              dataType: &quot;json&quot;,
              success: function(results) {
                  posts = results[&quot;posts&quot;].map(function (blogContent) {
                      if( blogContent.picture != '' ) {
                          return {
                              Title: blogContent.title ,
                              Picture: Content.urlPostPic + blogContent.picture ,
                              Video: '' ,
                              Text: blogContent.text ,
                              Datetime: blogContent.datetime ,
                          }
                      } else {
                          return {
                              Title: blogContent.title ,
                              Picture: '' ,
                              Video: blogContent.video ,
                              Text: blogContent.text ,
                              Datetime: blogContent.datetime ,
                          }
                      }
                  });
  
                  pagination = {pagination: results[&quot;pagination&quot;]};
  
                  var template = Handlebars.compile( $('#templateBlog').html() );
                  $('#blogPosts').append( template(posts) );
  
                  var template = Handlebars.compile( $('#templatePagi').html() );
                  $('#blogPagination').append( template(pagination) );
                                      // Here we call bindPagination &lt;===
                  bindPagination();
              }
          });
      },
  
  };
  
  Content.init();
  </code></pre>
  <p>You can see in the get BlogPosts function that I call BindPagination which is supposed to be this function, to prevent default behavior and call the content depending of the offset (pagination system)</p>
  <pre><code>function bindPagination() {
      
      console.log(&quot;bind&quot;);
  
      
      var links = $(&quot;#blogPagination ul a&quot;).map(function(e) {
          e.preventDefault();
          return this.href;
      }).get();
      console.log(links);
  
      $('#blogPagination').find('a').each(function(e) {
          console.log(&quot;clicked !&quot;);
          e.preventDefault();
          console.log($(this).attr('href'));
  
       //    var attr = this.attr();
          // var id = attr.replace(&quot;/&quot;,&quot;&quot;);
  
          // $('#blogPosts').empty();
          // $('#blogPagination').empty();
          // Content.getBlogPosts(id);
      });
  }
  });
  </code></pre>
  <p>the last }); stand for the end of the document ready.</p>