Search code examples
javascriptjqueryhtmlhref

Creating an a tag in JavaScript to add a link to a text line


I have researched a few suggestions on this, but most of them append the link to the body, not a line of text. For example, I want a webpage to say something like, "Live view image not currently available, redirect to Job Status page: Link text"

the code I have is: $('#counter').html('Live view image not currently available, redirect to Job Status page: Link text');

before I was adding the link I had $('#counter').html('Live view image not currently available') and that was working successfully.

Sorry the code I currently have is:

    $('#counter').html('Live view image not currently available, redirect to Job Status page: <a href="/jobs/status/?username='+username+'&token='+token+'&taskid='+taskId'">Link text</a>');

Solution

  • You were missing a + after the taskId variable:

    $('#counter').html('Live view image not currently available, redirect to Job Status page: <a href="/jobs/status/?username='+username+'&token='+token+'&taskid='+taskId+'">Link text</a>')
                                                                                                                                                                          ^