Jump to content

Change Attribute Of An Element


blob84

Recommended Posts

HI, I'm trying to change the attribute of an element,I have this function I want to change the style top and style left position of the second image cloned form the first,I think i need to use nodeValue to get the value of an attribute, but how can i do or there is another method?

<html><head><script type="text/javascript">function crea() {createImgAnanas = document.createElement("img");createImgAnanas.style.position="absolute";createImgAnanas.style.top="1%";createImgAnanas.style.left="25%"createImg1.style.zIndex="3";createImgAnanas.style.border="0";createImgAnanas.setAttribute("src", "http://www.fruechteadam.com/img/Ananas.jpg");createImgAnanas.setAttribute("id", "ananas1");createImgAnanas.setAttribute("alt", "ananas");createImgAnanas.setAttribute("title", "indicazione paese produzione ananas");createImgAnanas.setAttribute("width", "150");createImgAnanas.setAttribute("height", "79"); document.getElementById("prince").appendChild(createImgAnanas);createImgAnanas1 = createImgAnanas.cloneNode(true);  document.getElementById("prince").appendChild(createImgAnanas1);}</script><body id="prince"><input type="button" value="crea" onclick="crea();" /></body></html>

Link to comment
Share on other sites

why not just replace the top left with new valuescreateImgAnanas1 = createImgAnanas.cloneNode(true);createImgAnanas.setAttribute("id", "ananas2"); //need to replace id ref name as this must be uniquecreateImgAnanas1.style.top="1%";createImgAnanas1.style.left="50%"question: why add styling to image when you have assigned id ref to anyway? use css styling to this id ref<style type="text/css">#ananas1, #ananas2{border: 0pt none ; position: absolute; z-index: 3;}#ananas1{top: 1%; left: 25%;} #ananas2{top: 1%; left: 50%;}</style>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...