OffsetLeft and OffsetTop issue in IE
Solution 1
in IE should help:
var obj = target.getBoundingClientRect();
var left = obj.left;
var top = obj.top;
Solution 2
This is why you use a DOM library.
First potential problem I can see is the code
currObj.childNodes[2].childNodes[0].childNodes[1]
will only work in a cross-browser fashion if you have no "whitespace" in your DOM tree, since IE ignores html "whitespace" when populating the childNodes
property while other do not:
<div id="mydiv">
<span>Hello World</span>
</div>
IE will report mydiv.childNodes.length
as 1 (<span>
), everyone else 3 ("\n", <span>, "\n"
).
See Inconsistent Whitespace Text Nodes in Internet Explorer
Secondly, see @scunliffe's answer.
Abhimanyu
I have 7+ years of experience in I.T. Industry. • Excellent working knowledge in HTML, HTML5, XHTML, CSS 3, JavaScript, Jquery, Ajax, JSON, PHP, AngularJs. • Bootstrap, modernizr, Github • Expertise in Web Accessibility. • Responsive Designs • Creates UI standards and guidelines, • Search Engine Optimization (SEO). • Good knowledge of Dreamweaver, Photoshop. • Ability to multi-task in a fast-paced, deadline driven environment. • Good debugging and code optimization skills. • Cross Browser Compatibilities issues.
Updated on July 10, 2022Comments
-
Abhimanyu almost 2 years
Facing offsetLeft and offsetTop problem in IE while trying to create one tooltip which will create each time when we click on different events on calendar.. the following is the code which will work good for firefox but creating problem for IE. can tell me the solution for this..
var ttip = __createElement("div","ttipbox","ttipbox"); //creating div target = document.getElementById("sDiv"+ndiv); //taking the object of event on click of it tooltip has to display. var x = target.offsetLeft ; var y = target.offsetTop - (currObj.childNodes[2].childNodes[0].childNodes[1].scrollTop + ttip.offsetHeight); ttip.style.top= y+15; ttip.style.left= x - 80; ttip.style.zIndex= "2000";
Thanks in advance