0

I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I edited. Lines 75-75 & Lines 156-166

How would I get these edits from an external java-script file... I've tried for 3 hours to learn how to use "document.body.appendChild" "document.createElement" & "divTag.innerHTML" and I've gotten no where.

Thanks, Andrew Pearson

ps. This is my first post so if I did something wrong please tell me

Edit: this is what i've tired http://pastebin.com/ZaJJYsPq

   Potatoswatter you are correct

Edit: Sorry guys its late and my mind just isn't working how it should. What I'm trying to do is create Div and fill the div with the Lines I listed, but I want to do this with pure js since I can't do any major edits on the html page (I can only add external js to the head.

5
  • 1
    There's no JavaScript in the indicated edits. "How would I get these edits from an external java-script file..." — do you want JavaScript code that would add the those HTML elements to the page? Commented Jun 19, 2012 at 3:37
  • Do you want us to give you the JavaScript code that will do this edit instead of you? If so, show what have you tried already. Commented Jun 19, 2012 at 3:37
  • 1
    > I'm Learning Javascript Good for you Commented Jun 19, 2012 at 3:39
  • If you could try to show a simplified example of the problem (i.e. one that is less than 1000 lines of code) it'd be a lot easier on the eyes. Plus I'm not entirely sure what it is you are asking. What does "get these edits" mean? Commented Jun 19, 2012 at 3:48
  • @Andrew35133, pease make sure small samples of code that demonstrate your problem are present in the question. Rigth now there is no code in your question (links don't count). Commented Jun 19, 2012 at 4:19

2 Answers 2

2

So you want to know how to insert elements into DOM. Here are the links to MDN:

You can learn new things in MDN. It is a good reference site.

Sign up to request clarification or add additional context in comments.

Comments

0

From the little bit of JS you included, it looks like you're trying to create a div through pure JS, but your JS is wrong.

divTag.innerHTML = "<a class=\"sidetab\" href=\"#tab_dynmap\" id=\"tabhead_dynmap\"><img src=\"Images/DynMap.png\" alt=\"DynMap\" /><span>DynMap</span></a>";

You need to escape your quotes.

--

How would I get these edits from an external java-script file.

I'd copy and paste...

Lines 75-75 & Lines 156-166

These lines do not contain any JS:

 <a class="sidetab" href="#tab_dynmap" id="tabhead_dynmap"><img src="Images/DynMap.png" alt="DynMap" /><span>DynMap</span></a>

<div class="tabarea" id="tab_dynmap">
                        <h3>DynMap</h3>
                        <img src="Images/Map.png" alt="dynmap" class="tabimg"/>
                        <div class="tabcontents">
                            <div id="mapArea">
                                                <iframe src="http://mc.zephyrgaming.net/Dynmap/" height="500px" width="100%"> </iframe>
                            </div>
                        </div>
                    </div>

6 Comments

Right I am trying to create a div from pure js. So my problem is I'm not allowed to mess with the html body just the head. I need away to call a js to create the div i need :/ I'm just lost and its getting late so I'm mind is not working how it should.
For starters, your JS is invalid. Look at my comment, you need to escape your quotes.
Sorry I don't know what escape your quotes mean :/ I'm new at this, sorry
He means, since your markup string contains " <a class="<-- this, you need to escape it so that they are part of the string, and not interpreted as javascript code. You escape those using backslash (\): var string = "Alerting double quotes (\")"; alert(string);
Ohhh, now I see his example and how he "escaped". So when I'm writing js and I need to write html or something with a " that doesn't need to be read as js i need to put a \ in front of the "?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.