Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

Array ID as Div ID

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
Steve Tinsley
Asked:
Steve Tinsley
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
for example :
alert (rowData.id); //Displays Array ID
var htmlData = "<div class='rowData' id='" + rowData.id + "' style='display: none;'>";

Open in new window

0
 
leakim971PluritechnicianCommented:
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
 
mickey159Commented:
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
 
JRandelCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now