2

Can anyone please let me know what attributes I should use instead of these (which I have used for Internet Explorer) to work in chrome or firefox:

For changing visibility of an element:

obj.style.visibility = 'visible/hidden';

For getting the element:

document.getElementById("id");

For writing a string value into an element:

obj.innerHTML = "....";

To set or retrieve the left position of an object:

obj.style.posLeft/posTop = ...;

Or can anyone please suggest some article on browser compatibility?

epascarello
208k20 gold badges206 silver badges246 bronze badges
asked Oct 30, 2012 at 12:51
3
  • "please suggest some article on browser compatibility" - Do you want the red pill or the blue pill? Commented Oct 30, 2012 at 12:54
  • 1
    Only the last need to be changed to: obj.style.left/obj.style.top = '10px'; (must add px (or other unit) otherwise it won't work) Commented Oct 30, 2012 at 12:54
  • those statments work in pretty much, every browser, legacy or not. Commented Oct 30, 2012 at 12:54

3 Answers 3

5

obj.style.posLeft/posTop should be obj.style.left/top, and their value must always include a unit. Other than that, the snippets you showed should work on all browsers. Also, those positioning properties only work for elements that are not "statically" positioned, i.e., elements with position: absolute, position: relative or position: fixed.

answered Oct 30, 2012 at 12:54
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for the rapid reply, have you any article to which you refer to? How did you know this?
I know by experience, I've been using JavaScript for over a decade. I don't have any specific article to recommend, but I often check the MDN doc pages, which includes compatibility information for most functions. Another good reference is caniuse.com, where you can check the compatibility of many js functions, css properties and selectors, and html5 elements.
1

All are supported. You can check supported browsers at w3c. For example for posLeft http://www.w3schools.com/js/js_htmldom.asp

answered Oct 30, 2012 at 12:57

Comments

1

answers above are correct, but i'd like to add, that you'd better use any popular javascript framework to avoid things like:

window.screenY, window.screenX (for Firefox)
window.screenTop, window.screenLeft (for IE and Opera)

and other differences you will run into later

ps. http://caniuse.com/ is good too

answered Oct 30, 2012 at 13:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.