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

  • Home
  • SEARCH
  • 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 8526453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:16:37+00:00 2026-06-11T08:16:37+00:00

I want to focus an input element when a div is clicked. My HTML

  • 0

I want to focus an input element when a div is clicked.

My HTML looks like this:

<div class="placeholder_input">
    <input type="text" id="username" maxlength="100" />
    <div class="placeholder_container">
        <div class="placeholder">username</div>
    </div>
</div>

And my script is:

$("#username").focus(function() {
    $(this).next().hide();
});

$(".placeholder_input").mousedown(function() {              
    $(this).children(":first").focus();
});

When I click into the textbox, the placeholder text disappears correctly, but the blinking cursor doesn’t show in the textbox. (and I can’t type any text into the textbox)

Inside of the mousedown event handler, the $(this).children(":first") expression selects the correct input element, so I have no idea why the focus() call doesn’t work.

  • 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-06-11T08:16:38+00:00Added an answer on June 11, 2026 at 8:16 am

    It doesn’t work with the mousedown method; it does, though, work with the mouseup() and click() methods:

    $(".placeholder_input").mouseup(function() {              
        $(this).children(":first").focus();
    });​
    

    JS Fiddle demo.

    And:

    $(".placeholder_input").click(function() {              
        $(this).children(":first").focus();
    });​
    

    JS Fiddle demo.

    References:

    • click().
    • mouseup().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a page layout like this <input id=name class=mandotary type=text> <label for=name>Name must
I want to focus the first input element that is not type=hidden . I've
I want to achieve this effect: When the user focus a text area within
I want to set focus on the first form element in a div, either
Suppose I attach an blur function to an HTML input box like this: <input
I want to set focus on particular div using jquery or javascript. i have
function focus(element) { document.form.element.focus(); } I want to have a function to focus on
I want to set a text in a specific label on focus of an
I have a div element to which I am dynamically generating an input field
What I want : To, on focus, change one input box into another by

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.