admin管理员组文章数量:1327488
I have this code:
var bread = $('<li/>').html($('<a/>',{
href: '#',
text: 'Alle',
click: function(){ Diagnose.start() }
}));
bread += $('<li/>').html($('<a/>',{
href: '#',
text: data['icd1'].nummer,
click: function(){ Diagnose.icd(2,data['icd1'].id) }
}));
$('#side-panel2 .breadcrumb').html(bread.toString());
The problem is that the ouput is not the html i would like to have but instead its:
<ul class="breadcrumb" style="margin-top: 9px;margin-bottom: 0px;font-size:11px">
[object Object][object Object]
.....
First my code looked like this:
$('#side-panel2 .breadcrumb').html($('<li/>').html($('<a/>',{
href: '#',
text: 'Alle',
click: function(){ Diagnose.start() }
})));
$('#side-panel2 .breadcrumb').append($('<li/>').html($('<a/>',{
href: '#',
text: data['icd1'].nummer,
click: function(){ Diagnose.icd(2,data['icd1'].id) }
})));
This solution worked but i would like to change the html in one step because with the code from above a little delay can be seen! Thanks
I have this code:
var bread = $('<li/>').html($('<a/>',{
href: '#',
text: 'Alle',
click: function(){ Diagnose.start() }
}));
bread += $('<li/>').html($('<a/>',{
href: '#',
text: data['icd1'].nummer,
click: function(){ Diagnose.icd(2,data['icd1'].id) }
}));
$('#side-panel2 .breadcrumb').html(bread.toString());
The problem is that the ouput is not the html i would like to have but instead its:
<ul class="breadcrumb" style="margin-top: 9px;margin-bottom: 0px;font-size:11px">
[object Object][object Object]
.....
First my code looked like this:
$('#side-panel2 .breadcrumb').html($('<li/>').html($('<a/>',{
href: '#',
text: 'Alle',
click: function(){ Diagnose.start() }
})));
$('#side-panel2 .breadcrumb').append($('<li/>').html($('<a/>',{
href: '#',
text: data['icd1'].nummer,
click: function(){ Diagnose.icd(2,data['icd1'].id) }
})));
This solution worked but i would like to change the html in one step because with the code from above a little delay can be seen! Thanks
Share Improve this question edited Feb 28, 2014 at 13:49 user1636522 asked Feb 28, 2014 at 13:36 John SmithJohn Smith 6,26919 gold badges61 silver badges113 bronze badges2 Answers
Reset to default 3You can use .add() - not a concatenation operator because those are jQuery objects not strings
var bread = $('<li/>').html($('<a/>',{href: '#',text: 'Alle',click: function(){Diagnose.start()} }));
bread = bread.add($('<li/>').html($('<a/>',{href: '#',text: data['icd1'].nummer,click: function(){Diagnose.icd(2,data['icd1'].id)} })));
$('#side-panel2 .breadcrumb').empty().append(bread);
In short, in general:
$(".container").append( $("<a>A</a>"), $("<a>B</a>") );
Take a look on this DEMO.
本文标签: javascriptConcat two html elementsStack Overflow
版权声明:本文标题:javascript - Concat two html elements - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742198682a2431555.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论