#4448 closed bug (invalid)
$.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.
Change History (4)
comment:1 Changed 14 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 Changed 14 years ago by
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.
comment:3 Changed 14 years ago by
huh..... Firefox 3 works right,but in IE 7 still have some wrong link tags.
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...