Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to declare div inside javascript variable ?

Status
Not open for further replies.

Puma12

Programmer
Feb 14, 2013
3
NL
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:

JavaScript:
<div id="[b]mangodiv[/b]" style="display:none">
<li>
<iframe src="[URL unfurl="true"]http://www.mysite.com/?itemid=[/URL][b]mango[/b]&amp;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:

JavaScript:
<li><a href="#" onClick="divwin=dhtmlwindow.open('divbox', 'div', '[b]mangodiv[/b]', '[b]mango[/b]', '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:
HTML:
<head>
<link rel="stylesheet" href="windowfiles/dhtmlwindow.css" type="text/css" />

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

current code:
JavaScript:
[b]var itemName = 'mango'[/b]

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


This should be in forum216

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
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);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top