0

I'm trying to figure out why my JS files (script files) aren't loading when i load external content into my DIV with the id of content. I get the HTML and CSS but somehow the scripts doesn't load.

  • My index page (with head, body etc.. including scripts and css links) is showing on page load (inside #content DIV).

  • What am i doing wrong here? What would be the easiest way to include my script files on all my external pages which loads into my #content div?

Sample code to get a better picture of the problem situation:

    <a href="Link1">Link1</a>
    <a href="Link2">Link2</a>

    <nav>
        <div class="name">Erik</div>

        <a class="btn btn-1 btn-1a about" href="about" id="aboutbtn">About me</a>
    </nav> 

            <div id="content">

            </div>

Video link that explains what i've done so far (NOT MY VIDEO), without the explanation of how to include my script files: https://www.youtube.com/watch?v=ytKc0QsVRY4

If there are any questions just ask, and i will try to make it more clear!

Thanks beforehand! /// E

  • `Video link of what I've done` - seriously? You did that over four years ago and only ask the question now? Oh, wait, that's not a video of **what you've done** that's someone else's video and you don't understand it – Jaromanda X Jul 31 '16 at 06:02
  • Someone is a bit salty today? That is obviously what i meant *sigh*... I'm not claiming it's my video do i? I suggest you use your passionate energy on actually trying to help, then to talk down! Ah well ! Have a nice life! @JaromandaX – Erik Wahlström Jul 31 '16 at 18:06

1 Answers1

0

Whatever your using is phasing out the scripts, which is all good, because scripts have to work with the document as a whole not when it's fragmented.

You could load the scripts after the elements/HTML/CSS are appended to the document. I looked at your video and fair enough Jquery has a special method to load scripts and have them added to the program stack.

jQuery.getScript()

Check documentation:

https://api.jquery.com/jquery.getscript/

Throw that code into a separate .js file and load it in.

EDIT

Better yet use .appendTo() in your case:

http://jsfiddle.net/LeroyRon/bk9fryuj/

Leroy Thompson
  • 470
  • 3
  • 13