javascript - Adding a hyperlink dynamically in html using jquery -


for (i = 0; < crowcount / 5; i++) {     link = $('<a/>').attr({         href : '#',         id : $(this).attr('id') + (i + 1),         class: 'mylink'     });      $(this).append(link + "&nbsp;"); } 

when appending link component not giving me link. instead showing following thing without hyperlink.

 [object object] [object object] [object object] 

problem line $(this).append(link + "&nbsp;"); line converting object string, because appending object string

you can

html

<div>abc </div> 

code append

for (i = 0; < 10 / 5; i++) {     link = $('<a/>').attr({     href : '#',     id : $(this).attr('id') + (i + 1),     class: 'mylink'      });     link.html(i );  $("div").append(link );     $("div").html($("div").html() + "&nbsp;" ); } 

jsfiddle demo


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -