Side navigation
#4448 closed bug (invalid)
Opened March 30, 2009 07:11AM UTC
Closed March 30, 2009 10:51PM UTC
Last modified March 15, 2012 02:30PM UTC
$.getJSON() and append() link tags <a href>demo</a> sometimes is wrong
Reported by: | opengloves | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.4 |
Component: | data | Version: | 1.3.2 |
Keywords: | json and appden link tag | Cc: | |
Blocked by: | Blocking: |
Description
Good day!
I use jquery-1.3.2.min.js. I want append some link tags in a div, but something is wrong, against my expect.
some links are right, like this:
<a href="http://www.demo.com/123">demo</a>
but some are:
<a href="http://www.demo.com/123"/>demo
and these wrong tags was different is Firefox and IE 7.
For example such function:
json data:[{"linkKey":"http:://www.demo.com/123","linkValue":"demo"}]
html:
<div id="site"></div>
<div><a id="home">show</a></div>
$("#home").click(function(){
$.getJSON("demo.jsp",
function(json){
$.each(json,function(i){
$("#site").append("<span><a href="+json[i].linkKey+">"+json[i].linkValue+"</a></span>");});});});
To fix this, I have to change the function like this:
function(json){
$.each(json,function(i){
n = i+1;
$("site").append("<span><a id=id"+n+">"+json[i].linkValue+"</a></span>");
$("#id"+n).attr("href",json[i].linkKey);
});}
but this isn't suitable, I think.
Attachments (0)
Change History (4)
Changed March 30, 2009 10:51PM UTC by comment:1
resolution: | → invalid |
---|---|
status: | new → closed |
Changed March 31, 2009 07:43AM UTC by comment:2
Thank you for your response.
I quoted href attribute like this:
$("#site").append("<span><a href=\\""+json[i].linkKey+"\\">"+json[i].linkValue+"</a></span>");
and it works right. thank you very much.
Changed March 31, 2009 07:54AM UTC by comment:3
huh.....
Firefox 3 works right,but in IE 7 still have some wrong link tags.
Changed March 31, 2009 08:04AM UTC by comment:4
I thought this is sth. wrong in others libs. thanks again.
Your href attribute is not quoted in the HTML you generate, so it is being mis-parsed in some cases. Nothing jQuery can do about invalid HTML...