title: jQuery and Javascript - Set text box value to the text inside a link on href click
body: <p>I have a text input box and some links on a webpage. When I click on one of the links, I want to set the text of the search box to whatever the link text is. How do I do this? I have jQuery as well. I can't change the way the function executes though. I have to keep it as &quot;href=javascript:&quot;.</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 setText(this) {
          $("#searchBox").val(this);
      }</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;input type="text" id="searchBox"&gt;
      
      &lt;a class="link" href="javascript:setText(this)"&gt;Example 1&lt;/a&gt;
      &lt;a class="link" href="javascript:setText(this)"&gt;Example 2&lt;/a&gt;
      &lt;a class="link" href="javascript:setText(this)"&gt;Example 3&lt;/a&gt;
      &lt;a class="link" href="javascript:setText(this)"&gt;Example 4&lt;/a&gt;</code></pre>
  </div>
  </div>
  </p>