Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 499423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:59:02+00:00 2026-05-13T05:59:02+00:00

this is a really basic jQuery question, but i’m not sure how to do

  • 0

this is a really basic jQuery question, but i’m not sure how to do this:

<input type=text class=city />
<ul class="cityList">
    <li><a href="#">Test 1</a></li>
    <li><a href="#">Test 2</a></li>
    <li><a href="#">Test 3</a></li>
</ul>

What I want to do is to just get the Text (Test 1, 2 etc) of any clicked li a and put into the textbox

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:59:02+00:00Added an answer on May 13, 2026 at 5:59 am

    The following will do what you want.

    $('.cityList a').click(function (e) {
      $('input.city').val($(this).text());
      e.preventDefault();
    });
    

    How it Works

    $('.cityList a') returns an array of elements, bound with jQuery, that match the selector. In this case, all the links within any elements with a class of cityList.

    .click(...) adds an event to all items called upon, which is the previous array.

    function(){} is an anonymous function. When called, this is the element that has been clicked on. (Remember, this function represents the event we’re binding.)

    $('input.city') finds the textbox with the given class, but it could be multiple boxes. To prevent that, give it an ID in the HTML and change the selector to “#myID”.

    .val(...) sets the value of the textbox to the first parameter.

    $(this).text() will return the text of the link, which will be set as the textbox’s value (represented by the above code-ellipsis).

    e.preventDefault(); stops the browser from visiting the link that was just clicked. (However, this method will cancel any default behavior for any event.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is a really basic question but it's been really getting to
I know this is a really basic question but I've been searching the internet
This feels like a really basic question, but I can't figure it out anyway..
I realize this question is pretty basic, but I'm really stuck. I have a
I've just started learning jQuery/javascript, so this might seem like a really basic question,
Forgive the complete newbie question here - I know this is really basic stuff,
This question is really basic. What is the performance difference between removing a UIView
This is a really basic issue, but I'm new to perl and cannot work
This may seem like a realy basic question but... How do you use double
Sorry for asking a basic question like this but I've been reading on this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.