re1man
re1man

Reputation: 2367

Focus input box when a div is clicked

I have an input inside a div element (id = "edit). I was wondering how, onclick of the div area, I could activate the cursor in the input field.

Upvotes: 0

Views: 902

Answers (5)

rajsjha
rajsjha

Reputation: 1

use .attr() to add and removeAttr() to remove attribute "disabled" for the text box on the event click on the div.

Upvotes: 0

Arief
Arief

Reputation: 6085

use .focus() function like this:

$('#yourDiv').click(function() {
    $('#yourInput').focus();
});

Upvotes: 0

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114347

$('#edit').click(function() {
     $(this).find('input').focus()
})

Upvotes: 1

David
David

Reputation: 844

$("#myDiv").click( function() {
   $("#myTextField").focus();
});

Upvotes: 2

Rusty Fausak
Rusty Fausak

Reputation: 7525

You could use a <label for="edit"> element. That would focus the <input> element when clicked.

Upvotes: 3

Related Questions