Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  166] [ 6]  / answers: 1 / hits: 8953  / 10 Years ago, fri, february 28, 2014, 12:00:00

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


More From » jquery

 Answers
3

You 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);

[#47291] Thursday, February 27, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
finn

Total Points: 154
Total Questions: 88
Total Answers: 82

Location: Lithuania
Member since Mon, Nov 16, 2020
3 Years ago
;