Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this:</p> <pre><code>jQuery(function () { $('a').click(function (e) { e.preventDefault(); var name = $(this).text(); $("#selector").text(name); $("#textbox").val(name); }); }); </code></pre> <p><code>e.preventDefault()</code> will prevent the link from doing whatever it is doing by default (which sounds like it could be refreshing the page...).</p> <p><a href="http://jsfiddle.net/Town/Jxgwa/" rel="nofollow"><strong>Here's a demo</strong></a>.</p> <p>I've also amended your selectors - <code>p#selector</code> is inefficient, you should simply use <code>#selector</code> when selecting by ID, as documented in the <a href="http://api.jquery.com/id-selector/" rel="nofollow">jQuery API</a>.</p> <blockquote> <p>For id selectors, jQuery uses the JavaScript function document.getElementById(), which is extremely efficient. When another selector is attached to the id selector, such as h2#pageTitle, jQuery performs an additional check before identifying the element as a match.</p> </blockquote> <p><strong>EDIT:</strong> As it's become apparent that the click handler isn't what you need here, try this solution:</p> <p>Parse the URL to get the current page using a <a href="http://plugins.jquery.com/project/url_parser" rel="nofollow">jQuery URL Parser</a>, and then find the link that corresponds to the URL and get the text:</p> <pre><code>var url = "one.htm"; var linktext = $("a[href='" + url + "']").text(); $('#output').text(linktext); </code></pre> <p><a href="http://jsfiddle.net/Town/jhbYL/" rel="nofollow"><strong>Working demo of that bit</strong></a> (just do the URL parsing instead of setting the URL manually).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload