Reputation: 322
I have a simple stupid question. I want to add a URL which is clickable in JavaScript to my HTML
var a = document.createElement('a');
a.setAttribute('href', 'http://example.at');
$("#upcomingEvents").append('Please check our website. ' + a);
The URL appears, but it is not clickable, how can I change that?
Thanks!
Upvotes: 0
Views: 216
Reputation: 31131
You have to put some text inside the link so there is something to click:
a.innerText='click me!';
And then you can't concatenate a string to a DOM element.
$("#upcomingEvents").append('Please check our website.');
$("#upcomingEvents").append(a);
Upvotes: 2
Reputation: 57719
Try it like this:
$("#upcomingEvents").append('Please check our website. ');
$("#upcomingEvents").append(a);
The +
operator causes the DOMNode to be cast to a string, you don't want that.
Upvotes: 2