Reputation: 257
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>
Upvotes: 1
Views: 154
Reputation: 268354
Javascript doesn't change the physical markup on the page. It changes the DOM. The DOM is constructed from the markup, but after that the markup isn't crucial.
You don't want to alert the HTML
, you want to alert the value of the input:
alert($("#test :input[name='sum']").val());
Upvotes: 3
Reputation: 2277
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.
Upvotes: 1