4
<div class="ctrlHolder">
<label for="" id="name.label">Name</label>
<input name="name" id="name" type="text" class="textInput small" />
<p class="formHint">The name of the item you are submitting</p>
</div>

How can I insert predefined text into a input element. I'd like this function to active when the user doubleclicks the label element.

$('#name.label').dblclick(function(){
    $('#name').val('some text');
});
1
  • 2
    I would be cautious to use dots in element identifiers as they may or may not confuse the jQuery selectors: #name.label matches an element that has both id="name" and class="label". Commented Feb 10, 2011 at 19:03

2 Answers 2

7

here check this fiddle

you can use .text("yourPreDefinedText") to replace the text of an element

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for that example. However, I would like to be able to change the value of the input element not the label. When I try it doesn't seem to work.
When the lable is double clicked, not the input
It's working well in the example. I can't get it to work on my site here: tinyurl.com/6gcwkg2
to insert inside input : $("#inputID").val("theText");
1

$('#name.label') will cause jQuery to look for an element with id "name" and class "label". I believe the code above should work if you rename the label's id to something like "name-label".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.