2

Here is the sample of code that I've concentrating on. I've tried to incorporate it with my test site and the code doesn't work. I don't understand why, in both instances I'm using the latest version of Jquery (1.5) I'm using Google's hosted Api for my test site.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>

<script>
  $('#name-label').dblclick(function() {
    $("#name").val('some text');
  });
</script>

<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>
Ambo100
  • 1,075
  • 3
  • 15
  • 28

2 Answers2

4

Does wrapping it in a $(document).ready(function() {}); work?

$(document).ready(function() {
    $('#name-label').dblclick(function(){
        $("#name").val('some text');
    });
});
Nathan Anderson
  • 6,522
  • 23
  • 29
  • 1
    Good. As a rule of thumb, it is best to wrap your code in a `$.ready()` function, as this will make sure the DOM is completely loaded before your code tries to execute. What was happening before is you were trying to get a reference to the element `name-label` before it had been loaded into the DOM. – Nathan Anderson Feb 10 '11 at 23:13
-1
$(function() {
  $('#name-label').dblclick(function(){
      $("#name").val('some text');
  });
}
bobgubko
  • 565
  • 4
  • 15