Link to home
Start Free TrialLog in
Avatar of omicronpersei8
omicronpersei8

asked on

How to put a DIV tag around another tag in Javascript

1. I need to know how to put a div around a object on the page. I have <object></object> and I want it to be <div><object></object></div> from within javascript. It should work in IE and Moz and it should only put the div around the requested element.

Here is my javascript so far:

// get element on page. this element is in body tag with other elements after it
var myEl = document.getElementById("myElementID");

// create div to surround only the above element
var myDiv = document.createElement("div");
myDiv.style.position = "absolute";
myDiv.style.zIndex = 100;
// this works for IE and Mozilla
myDiv.style.left = 10+"px";
myDiv.style.top = 10+"px";
myDiv.style.height =400+"px";
myDiv.style.width = 300+"px";
myDiv.style.overflow = "auto";

// not sure what to do here...
SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of omicronpersei8
omicronpersei8

ASKER

CobolD - i see that your answer could have worked had we had the chance to discuss it.
Zvonko - your solution worked. thank you. i appreciate the full example. it helps to show a full working example. cause then i know if something goes wrong in my project it's because i didn't implement it right.
superm401 - you're answer would have lead me to the final solution.
GwynforWeb - i appreciate that you provided another solution even though Zvonko provided a working solution. i like that you expressed your idea.
Thanks for the feedback omicronpersei8 .
I appreciate your generosity.