0

Upon clicking a button, I load some extra html in my site, which I keep in a different file. After loading it, I want to make some changes in the loaded html. I currently try to do this as follows:

$.when($("#divForInsert").load("/toInsert.html")).done(function(){
    $("#someInput").val("new text in it");
});

The contents of the file are as follows:

<input type='text'
   size='5'
   id='someInput'
   name='someInput'>

I am sure that #someInput exists (checked it in toInsert.html and with inspect element in the browser) and since I load it using .done(), I suppose it's already loaded when I try to change the val of it. So why does it refuse to be changed?

All tips are welcome!

[EDIT] I incorrectly said it was a div I tried to change, but it was actually an input field. I added it to the question.

2
  • Try using $('#someDiv').html('content') Commented Jul 5, 2014 at 0:55
  • @doitmyway - Excuse me, but I mistakenly said it was a div, where it was actually an input field of which I'm trying to change the val. I changed it in my initial question. Would you have any ideas now? Commented Jul 5, 2014 at 1:11

1 Answer 1

1

Try this:

$("#divForInsert").load("/toInsert.html", function() {
    $("#someInput").val("new text in it");
});
Sign up to request clarification or add additional context in comments.

2 Comments

Excuse me, but I mistakenly said it was a div, where it was actually an input field. I changed it in my initial question. Would you have any ideas now?
Awesome! Nailed it! Thanks a million!

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.