Solved

Array ID as Div ID

Posted on 2011-03-17
4
381 Views
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 $rowData.id rather than (for example) 56.
Im sure its a simple one but I am stuck :(

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

Open in new window

0
Comment
Question by:Steve Tinsley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

Accepted Solution

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

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 35160057
Another one (using appendChild method instead innerHTML attribute) :
alert (rowData.id); //Displays Array ID

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

document.getElementById("anotherDivSomewhereInThePageOrAnyOtherContainer___ID").appendChild(myDiv);

Open in new window

0
 
LVL 6

Expert Comment

by:mickey159
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!
0
 
LVL 1

Expert Comment

by:JRandel
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 (rowData.id); //Displays Array ID
var htmlData = "<div class='rowData' id='" + rowData.id + "' style='display: none;'>";

Open in new window

0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JQuery on multiple lines 3 48
Why am I getting SyntaxError: missing ; before statement error 39 81
jQuery element reference issue 2 38
Bootstrap NavBar Not Working 2 29
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

739 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