bennyboywonder Posted March 5, 2007 Share Posted March 5, 2007 I am trying to make a cross-browser getById and getStyle function to use with my other javascripts; at present to use these in conjunction with each other, I would have to write it like this var mystyle = getStyle(getById("addcat")) I think function getById(whichLayer) { this.getStyle = getStyle; object = document.getElementById ? document.getElementById(whichLayer) : document.all ? document.all[whichLayer] : document.layers ? document.layers[whichLayer] : false; return object } function getStyle(obj) { var object = obj.style ? obj.style : obj; return object; } is their a way of writing an object so that I could use standard dot syntax, ie var mystyle = getById("addcat").getStyle; I was thinking something along the lines of var browsers = new browserObject(); var mystyle = browsers.getById("myid").style; mystyle.left = "10"; function browserObject() { this.getById = function(whichLayer) { this.style = getStyle; object = document.getElementById ? document.getElementById(whichLayer) : document.all ? document.all[whichLayer] : document.layers ? document.layers[whichLayer] : false; return object } } function getStyle(obj) { var object = obj.style ? obj.style : obj; return object; } though this is just a guess of the sort of thing I am after, and I know this doesn't work. Quote Link to comment Share on other sites More sharing options...
fenway Posted March 5, 2007 Share Posted March 5, 2007 But getElementById is cross-browser... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.