Why is my new element wrapped in an array?
$('<a>')
[<a></a>]
When I try to use it with appendChild I get a dom exception 8 error.
Edit: That was an example. My exact code is
addendum = $("<a>", {href: download_url, text:"Download .nupkg file"})
badge = $(".nuget-badge")[0]
badge.appendChild(addendum)
All jQuery objects are array-like objects. Selecting the first element in the collection with
[0]will return just the one element. If you instead log the jQuery object, it will appear to be an array in the console.Note, jQuery has a built-in method called .append that should do what you want.
or
or for your given code:
or (preferred)