title: How to check if href attribute contains a string?
body: <p>I want to get all "a" tags from page, get its "href" attribute and check if in this href is text ".pdf". So I get all <code>a</code> tags into <code>tags</code> variable, then with <code>each()</code> function I check every "a" (as a <code>tag</code>). But code:</p>
  
  <pre><code>  if ($(tag).indexOf('.pdf') &gt; 0) 
      console.log($(tag));
  </code></pre>
  
  <p>is not working. Why? Why I can't use <code>indexOf</code> on <code>href</code>? I tried with <code>search()</code> function, but it's also not working.</p>
  
  <p>So I thought - ok, there's something wrong with this <code>href</code>. Lets take it as a text.</p>
  
  <p>But code:</p>
  
  <pre><code>  var text = $(tag).text();
      console.log(text);
  </code></pre>
  
  <p>is also not working. Can anybody tell me why?</p>
  
  <p>Code snippet has errors intentionally - to show with what I have a problem.</p>
  
  <p>Thank you in advance.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>(function($){
    var tags = $('a');
    $(tags).each(function() {
          var tag = $(this).attr('href')     
          
          if ($(tag).indexOf('.pdf') &gt; 0) 
            console.log($(tag));
              
          var text = $(tag).text();
          console.log(text);
    });
  }(jQuery));</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;html&gt;
    &lt;a href="https://www.test.com/example.pdf" target="_blank"&gt;Link with ".pdf"&lt;/a&gt;
    &lt;a href="https://www.test.com/" target="_blank"&gt;Link without ".pdf"&lt;/a&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>