N. Sch N. Sch - 1 year ago 68
jQuery Question

How To Create A Link In Jquery

I will be very grateful to anyone who can answer me. No matter what I do it does not display as a link rather it displays in HTML how do I fix this?

for (t = 0; t < jobs.length; ++t) {

$(".space").val('<a href="http://localhost:53112/category/c?id=" + jobs[t].Id>jobs[t].Occupation jobs[t].Years</a>')

Answer Source

You should use jQuery.append(), if you are adding multiple links. jQuery.html() will keep overwriting the previous link.

for(var t = 0; t < jobs.length; ++t) {
    var href = 'http://localhost:53112/category/c?id=' + jobs[t].Id;
    var text = jobs[t].Occupation + ' ' + jobs[t].Years;
    $('.space').append($('<a/>').attr('href', href).text(text));