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></di v> 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("m yElementID ");
// create div to surround only the above element
var myDiv = document.createElement("di v");
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...
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("m
// create div to surround only the above element
var myDiv = document.createElement("di
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the feedback omicronpersei8 .
I appreciate your generosity.
ASKER
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.