Note that there are some explanatory texts on larger screens.

plurals
  1. POUse Basic Javascript Function to Insert Code into Div
    primarykey
    data
    text
    <p>I am trying to call up an "example.js" file containing an image gallery (the bulk of the code for the gallery, seeing as how i will have 3 to choose from) using:</p> <pre><code>&lt;img src="img.jpg" onClick="thisAction()" /&gt; </code></pre> <p>What I want to do is place all of the contained "example.js" code within a div elsewhere in the page. I have a seperate javascript.js file that references the thisAction() function, but I can't seem to figure out where to go from there, nothing is working. I have tried a load function, and I've delved into ajax, not really knowing what I'm doing... Please help!</p> <hr> <p>Ok, so just to clarify ^^^above^^^, I am not actually trying to call in any javascript in my "example.js", I was simply instructed to do so, because of some reason I can't recall that had to do with recognizing the formatting.... because what I actually want is some html to be inserted, which includes some divs. What i'd like, if possible, is to insert all the code in "example.html" which may contain something like this:</p> <pre><code>&lt;div id="navbuttonleftcontainer"&gt;&lt;/div&gt; &lt;div id="image_holder"&gt;&lt;img src="examplepic.jpg" /&gt;&lt;/div&gt; &lt;div id="navbuttonrightcontainer"&gt;&lt;/div&gt; </code></pre> <p>into a div elsewhere on the page in my existing "gallery.html" by calling the function with the </p> <pre><code>&lt;img src="examplenavpic.jpg" onClick="thisAction() /&gt; </code></pre> <p>tag.</p> <p>The closest I've been able to come was with this:</p> <pre><code>function thisAction() { $('#divonmygalleryhtml').html('gallery1.html'); } </code></pre> <p>But this doesn't actually spit out the above mentioned example.html code, it just puts the text "gallery.html" into the div. I've tryed simply copying all the code from example.html and replacing it with </p> <pre><code>function thisAction() { $('#divonmygalleryhtml').html(' &lt;div id="navbuttonleftcontainer"&gt;&lt;/div&gt; &lt;div id="image_holder"&gt;&lt;img src="examplepic.jpg" /&gt;&lt;/div&gt; &lt;div id="navbuttonrightcontainer"&gt;&lt;/div&gt; '); } </code></pre> <p>But that won't do a thing... Ive tried the last 2 suggestions with no luck... Any suggestions would be great.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload