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. Link to comment https://forums.phpfreaks.com/topic/41294-cross-browser-getbyid-function/ Share on other sites More sharing options...
fenway Posted March 5, 2007 Share Posted March 5, 2007 But getElementById is cross-browser... Link to comment https://forums.phpfreaks.com/topic/41294-cross-browser-getbyid-function/#findComment-200096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.