<script>_x000D_
_$ = document.querySelector .bind(document) ;_x000D_
_x000D_
var AppendLinkHere = _$("body") // <- put in here some CSS selector that'll be more to your needs_x000D_
var a = document.createElement( 'a' )_x000D_
a.text = "Download example" _x000D_
a.href = "//bit\.do/DeezerDL"_x000D_
_x000D_
AppendLinkHere.appendChild( a )_x000D_
_x000D_
_x000D_
// a.title = 'Well well ... _x000D_
a.setAttribute( 'title', _x000D_
'Well well that\'s a link'_x000D_
);_x000D_
</script>
_x000D_
The 'Anchor Object' has its own*(inherited)* properties for setting the link, its text. So just use them. .setAttribute is more general but you normally don't need it. a.title ="Blah"
will do the same and is more clear!
Well a situation that'll demand .setAttribute is this: var myAttrib = "title"; a.setAttribute( myAttrib , "Blah")
Leave the protocol open. Instead of http://example.com/path consider to just use //example.com/path. Check if example.com can be accessed by http: as well as https: but 95 % of sites will work on both.
OffTopic: That's not really relevant about creating links in JS
but maybe good to know:
Well sometimes like in the chromes dev-console you can use $("body")
instead of document.querySelector("body")
A _$ = document.querySelector
will 'honor' your efforts with an Illegal invocation error the first time you use it. That's because the assignment just 'grabs' .querySelector (a ref to the class method). With .bind(...
you'll also involve the context (here it's document
) and you get an object method that'll work as you might expect it.