javascript - FInd out position of html element in iframe -
i want find out position of element in iframe. trying ot use:-
//function find position of element on page function getelementposition(elem){ var posx = 0; var posy = 0; while(elem!= null){ posx += elem.offsetleft; posy += elem.offsettop; elem = elem.offsetparent; console.log("in function:" + elem.tagname + " " + posx + " " + posy); } return { x : posx, y : posy }; } to list of elements of iframe,
var doc1 = $('#page1').get(0).contentdocument; // page1 id of iframe element var list1 = doc1.getelementsbytagname('*'); console.log(list1.length); // printing correctly var index = prompt("enter element index"); var elem1 = list1[index]; var pos1 = getelementposition(elem1); console.log("positions:" + pos1.x + " " + pos1.y); but not working. elem not null elem.offsetparent null in every case. doing wrong ?
for elements, working fine. elements, offsetparent coming null , offsetleft 0 , offettop 0.
is there other way find out position of each element.
thanks in advance..
you appear using jquery. why not let jquery heavy lifting you?
Comments
Post a Comment