Ok hello again guys,
Sorry to keep bugging you guys with my failings but I can't get my 'dot notation' to work.
Basically I'm trying to be able to target where the css change happens. My method for doing this works like this:
<div rstyle="#myDiv.border:solid 1px #000000"></div>
<div id="myDiv"></div>
So what happens is I check for '.' and if the exist I split() the string and remove the # (the # is the indicator it is a reference to an ID and not a class). Then I'm trying to apply the rollover effects to that div using getElementById(). In theory it all souns feasible, but I can't get it to work - I just keep getting errors like 'object does not support this method'.
My Current script (without ID checking):
code:
<script type="text/javascript">
var overStyler = {
/*-----------element check-----------*/
obj: document.getElementsByTagName ? document.getElementsByTagName("*") : null,
/*----------------end----------------*/
setup: function() {
for(i=0;i<overStyler.obj.length;i++) {
/*------------rstyle check-----------*/
if(overStyler.obj[i].getAttribute && overStyler.obj[i].getAttribute('rstyle')) {
cssValues = overStyler.obj[i].getAttribute('rstyle').split(/;/);
/*----------------end----------------*/
overStyler.obj[i].orig = new Object();
overStyler.obj[i].over = new Object();
for (j=0;j<cssValues.length;j++) {
/*--------------css2jss--------------*/
if (/-/.test(cssValues[j])){
z = cssValues[j].toLowerCase().split('-')
x = z[1].charAt(0).toUpperCase() + z[1].substring(1, z[1].length)
cssValues[j] = z[0]+x;
}
/*----------------end----------------*/
styleType = cssValues[j].split(/:/)
selector = styleType[0]
newValue = styleType[1]
/*--------undefined style fix--------*/
overStyler.obj[i].style[selector]?
overStyler.obj[i].orig[selector]=overStyler.obj[i].style[selector]:
overStyler.obj[i].orig[selector]=0
/*----------------end----------------*/
overStyler.obj[i].over[selector] = newValue;
}
/*----------------over---------------*/
overStyler.obj[i].onmouseover = function() {
for(prop in this.over) {
this.style[prop] = this.over[prop];
}
}
/*----------------end----------------*/
/*----------------out----------------*/
overStyler.obj[i].onmouseout = function() {
for(prop in this.orig) {
this.style[prop] = this.orig[prop];
}
}
/*----------------end----------------*/
}
}
}
}
onload = overStyler.setup;
</script>
And this is the sort of code I have been trying to squeeze in to check for IDs (and classes eventually):
code:
/*---------------------------------*/
if(selector.match(/\./)){
sel = selector.split(/\./)
if(/#/.test(sel[0])){
sel[0]=sel[0].replace(/#/,'')
overStyler.obj[i] = document.getElementById(sel[0])
}
selector = sel[1]
}
/*---------------------------------*/
[This message has been edited by smonkey (edited 09-10-2003).]