Side navigation
#4816 closed bug (invalid)
Opened June 25, 2009 07:27AM UTC
Closed October 03, 2009 01:20AM UTC
val function has BUGs
Reported by: | jennal | Owned by: | john |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | selector | Version: | 1.3.2 |
Keywords: | input val value | Cc: | |
Blocked by: | Blocking: |
Description
I clone a div node from the page, it contains a input node. At this moment, the new node haven't been insert into document yet. Then I use find to get the input node from the div node, and use val("Something") to change its value, it doesn't work, even I use attr("value", "Something"), it is the same. I think it is a bug, while I can setup other attributes.
code like this:
var node = $("#" + this.templateId).clone();
node.find("input.title").val(this.title);// or node.find("input.title").attr("value", this.title);
Attachments (0)
Change History (4)
Changed June 26, 2009 02:02AM UTC by comment:1
Changed June 26, 2009 09:10PM UTC by comment:2
I'm sorry to post this immediately as a bug, and haven't test enough. BUT, I think this is really a BUG. And I'm sorry to post this as a val() BUG, I think it's html() BUG now.
Here is the code, what BUG happens:
<!DOCTYPE HTML PUBLIC "-W3CDTD HTML 4.01EN" "http:www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test JQuery</title>
</head>
<body>
<div id="page">
</div>
<div id="template" style="display:none;">
<input class="text" type="text" />
<input class="hidden" type="hidden" />
</div>
<script type="text/javascript" src="jquery-1.3.2.min.js">
</script>
<script type="text/javascript">
$().ready(function(){
var node = $("#template").clone();
node.find(".text").val("Test"); does not work
node.find(".text").attr("value", "Test"); does not work
node.find(".text").attr("id", "ID");works
node.find(".hidden").val("Test");works
does not work
$(node.html()).appendTo($("#page"));
works, but not what i wanted, i wish to replace some words of the html, and i want it's children only
node.clone().appendTo($("#page"));
});
</script>
</body>
</html>
PS:
This is tested on IE6 and FF3.
IE6 works, but FF3 not.
You would test that and found the value of hidden input could be setted, but visible not.
Changed June 26, 2009 09:14PM UTC by comment:3
This code is more clear:
<!DOCTYPE HTML PUBLIC "-W3CDTD HTML 4.01EN" "http:www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test JQuery</title>
</head>
<body>
<div id="page">
</div>
<div id="template" style="display:none;">
<input class="text" type="text" />
<input class="hidden" type="hidden" />
</div>
<script type="text/javascript" src="jquery-1.3.2.min.js">
</script>
<script type="text/javascript">
$().ready(function(){
var node = $("#template").clone();
node.find(".text").val("Test"); /*does not work*/
/*node.find(".text").attr("value", "Test"); /*does not work*/
node.find(".hidden").val("Test");
/*does not work as i want it be*/
$(node.html()).appendTo($("#page"));
/*works, but not what i wanted, i wish to replace some words of the html, and i want it's children only*/
/*node.clone().appendTo($("#page"));*/
});
</script>
</body>
</html>
Changed October 03, 2009 01:20AM UTC by comment:4
resolution: | → invalid |
---|---|
status: | new → closed |
The .clone() method clones the nodes *and selects the clones.*
http://docs.jquery.com/Manipulation/clone
In your example, you are finding and changing the cloned nodes, which are not in the document.
Please provide a full test case with HTML and script. It's not clear what the HTML for your example might look like. Also let us know what browsers you used for testing.
For future reference, it's best to ask about things like this on a forum before posting a bug.