I want to add additional scripts and styles to my site when a specific div is loaded. I start out by defining a path to either a script or stylesheet and then create an element. Hereafter I append the element to the head tag in HTML.

But I would like a way to see if the script or stylesheet already has been append before I append it again. It would be stupid to append an already existing script or stylesheet.

Q: How do I use javascript to check wether or not a script already exists in the head tag, and then append the element if not?

EDIT

I have made a function based on the answer from @KernelPanik. It doesn't work yet but hopefully it will. The function is currently in question: my script appending function doesn't work

Edit
Report