Array ID as Div ID

Posted on 2011-03-17
Last Modified: 2012-05-11
How do I use data from an array as the DIV ID? As you can see in my snipit code below, I am alerting to the screen the ID element of the array which works fine.

When I put that data in as the DIV ID it just prints out $ rather than (for example) 56.
Im sure its a simple one but I am stuck :(

alert (; //Displays Array ID
var htmlData = "<div class='rowData' id=$ style='display: none;'>";

Open in new window

Question by:sjtinsley83
  • 2
LVL 82

Accepted Solution

leakim971 earned 500 total points
ID: 35160032
for example :
alert (; //Displays Array ID
var htmlData = "<div class='rowData' id='" + + "' style='display: none;'>";

Open in new window

LVL 82

Expert Comment

ID: 35160057
Another one (using appendChild method instead innerHTML attribute) :
alert (; //Displays Array ID

var myDiv = document.createElement("div");
//myDiv.setAttribute("id") =; =; = "none";


Open in new window


Expert Comment

ID: 35205816
I believe that you are using Dreamweaver's PHP code.
You are trying to add the id from the id of the database,right?
Please post a complete example for closer investigation and a better answer.

Good luck!

Expert Comment

ID: 35299255
I may have misread the question but wouldn't the solution be as simple as adjusting the example code posted to the following (posted below).

Note that you would then take the contents of htmlData  and add it to the html element of choice (via append, after, before, prepend etc)
alert (; //Displays Array ID
var htmlData = "<div class='rowData' id='" + + "' style='display: none;'>";

Open in new window


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol ( or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now