views:

44

answers:

2

Hi everyone,

I would know if this is a bug... When I alert html content from #test, I get :

<input name="sum" value="" type="text">

whereas it was set to 55 just before the alert, and I can view it on the brower.

Can you tell me why ? :-)

    <div id="test">
    <input type="text" name="sum" value="">
</div>

<script language="javascript">
 $(document).ready(function() {
    $("#test").find("input[name='sum']").val(55);
    alert($("#test").html());
 });
 </script>
+3  A: 
Jonathan Sampson
+1  A: 

This is not a bug. The value of #test is not part of the HTML content of the input -- it was set after the element was inserted into the DOM -- and thus the html() function doesn't return it.

eliah
Ok thanks, I thought that html() function would change according to updates from children...
Tom
If you'd added more elements (for instance) inside the div, html() would return them, but changing attribute values is not reflected. I think.
eliah
Is there a way to see how the source looks really like ?Thanks !
Tom
That's kind of a tricky question. Arguably, the source of the page doesn't include the value that you've set later. But to answer your question more helpfully, http://stackoverflow.com/questions/1388893/jquery-html-in-firefox-uses-innerhtml-ignores-dom-changes is another discussion of this issue, which provides a jQuery plugin you could use.
eliah
Thanks a lot for your help eliah !
Tom