JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 2nd, 2013, 05:08 PM
yousg27 yousg27 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 yousg27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 10 sec
Reputation Power: 0
Question Other - Inject new div into the page

Hello

Code:

var temp = 1;  

document.getElementById('display').innerHTML +="<div id = \"temp\">  Here will be some image that will go to that div  </div>




I'm using the above code to inject a new div that has some images in to the " display " div in the body of the page.

Code:
<div id = \"temp\"></div>


the div id is set t a java script variable that changes. I tried the above and other syntax and it did not work.

I want the div id name to increase every time this function is called.

please help

thanks.

Reply With Quote
  #2  
Old January 3rd, 2013, 07:54 AM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 605 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 17 m 48 sec
Reputation Power: 69
You need to increment the "temp" variable; like so:

Code:
<script>
var temp = 0;
function injectDIV()
{
temp++;
document.getElementById("display").innerHTML += "<div id = \""+temp+"\">  Here will be some image that will go to that div  </div>";
}
</script>

<span id="display"></span>

<input type="button" value="Inject New Content" onclick="injectDIV()"/>

Reply With Quote
  #3  
Old January 3rd, 2013, 05:02 PM
yousg27 yousg27 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 yousg27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 10 sec
Reputation Power: 0
Thanks alot.

I was missing to add the + variable +. The plus sign and this caused me lots of time.

What is a good way of learning java script and all syntax

Reply With Quote
  #4  
Old January 3rd, 2013, 07:55 PM
AndrewSW's Avatar
AndrewSW AndrewSW is offline
JavaScript is not spelt java
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2011
Location: Landan, England
Posts: 743 AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level)AndrewSW User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 23 h 1 m 13 sec
Reputation Power: 164
Quote:
Originally Posted by yousg27
Thanks alot.

I was missing to add the + variable +. The plus sign and this caused me lots of time.

What is a good way of learning java script and all syntax


Most online JS tutorials seem to be out-dated - unless someone can recommend an up-to-date site?

So I would recommend a book: JavaScript and jQuery: The Missing Manual, D S McFarland sounds good! (I haven't read it but his CSS, Missing Manual was very good.)

javascript: The Definitive Guide is an excellent book, but not an introductory text. The Missing Manual will be an easier introduction/tutorial.
__________________
"The mysql extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used." the docs

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Other - Inject new div into the page

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap