<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');
});
<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');
});
Share
Improve this question
edited Feb 10, 2011 at 18:57
Ambo100
asked Feb 10, 2011 at 18:38
Ambo100Ambo100
1,1893 gold badges15 silver badges29 bronze badges
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". – Aleksi Yrttiaho Commented Feb 10, 2011 at 19:03
2 Answers
Reset to default 7here check this fiddle
you can use .text("yourPreDefinedText") to replace the text of an element
$('#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".