INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to declare div inside javascript variable ?

How to declare div inside javascript variable ?

(OP)
I got a javascript variable(siteContents) i want to add a dynamic div to it with hyper link that pops it up . The dynamic div has dynamic div id and dynamic frame url.The button that activates the dynamic div also got dynamic name and dynamic value.

could any one show me how i can add both dynamic div and its button to siteContents variable ?


Note1: all dynamic values shown in bold.
Note2:dynamic value = itemName.


This is dynamic div that i want to add to my siteContents variable:

CODE --> javascript

<div id="mangodiv" style="display:none">
<li>
<iframe src="http://www.mysite.com/?itemid=mango&bgcolor=white" style="border: medium none;" height="300" width="450"></iframe><br>
</li>
</div> 

This is hyperlink that activates the above dynamic div. I want to add this too my siteContents variable:

CODE --> javascript

<li><a href="#" onClick="divwin=dhtmlwindow.open('divbox', 'div', 'mangodiv', 'mango', 'width=450px,height=300px,left=200px,top=150px,resize=1,scrolling=1'); return false"><b>Create/ Open Window 4</b></a></li> 

this is the part that activates the popup div:

CODE --> html

<head>
<link rel="stylesheet" href="windowfiles/dhtmlwindow.css" type="text/css" />

<script type="text/javascript" src="windowfiles/dhtmlwindow.js">
</script>
</head> 

current code:

CODE --> javascript

var itemName = 'mango'

var siteContents = "<li>"
   +"<iframe src='https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTeUusgzharBX4HTwmQHNZOimpaCGRBx4CLKNJAiLjUVi12VN66' height=200 width=200 style='border: none;'></iframe><br>"
   +"<div class='details'>"
   +"<div class='title'>"
   +"<a href='https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTeUusgzharBX4HTwmQHNZOimpaCGRBx4CLKNJAiLjUVi12VN66' target=\"_blank\"'>"+itemName+"</a><br>"
+"</div></div></li>";
 document.getElementById("myDiv").innerHTML += siteContents;
<ul id="myDiv"></ul> 

RE: How to declare div inside javascript variable ?

Quote:

could any one show me how i can add both dynamic div and its button to siteContents variable?
Just like you would concatenate any string.

ALSO use single quotes as string delimiters and escape the double quotes.

eg:
+'<div class=\"details\">';

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: How to declare div inside javascript variable ?

AND


This should be in forum216: Javascript

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: How to declare div inside javascript variable ?

agreed with the forum clarification, but to quickly answer the question, try this:

CODE

var newdiv = document.createElement('div');
var divIdName = 'myDiv';
newdiv.setAttribute('id',divIdName); 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close