J
Jim Ley
Hi,
IE has the ability to setExpressions on stylesheets so you can
calculate the value of the css property through script.
For various reasons I'm wanting to use a side-effect of this to attach
an event to every element of a class in a document (I'm including
content from a lot of large 3rd party content, and iterating over the
entire DOM searching for the classes and then attaching the event is
proving too slow, aswell as being too late post-load as the pages are
long and interaction would ideally occur before onload fires, it's an
embedded IE only solution.)
The solution I'm using is:
<URL: http://jibbering.com/2004/1/setExpression.html >
<style type="text/css">
.chicken {
color:green;
moomin:expression(snork(this));
}
</style>
<script type="text/jscript">
statusCount=0;
function snork(el) {
el.onclick=handler;
window.status=++statusCount;
}
function handler() {
alert("Hi!");
}
</script>
</head>
<body>
<p class="chicken">
A paragraph.
</p>
Obviously this is far from ideal as it means that the onclick handler
is attached everytime the css is evaluated (and this is often!) so I
need to remove the rule after attaching it. However I can't find a
way of doing this!
Changing the className of the objects to something else doesn't
achieve it, playing with the style or runtimeStyle of the object
doesn't, calling removeExpression on the elements style doesn't do
anything. So nothing on the element itself seems to achieve it.
Turning to the stylesheet, none of disabling the entire stylesheet,
removing the rule, changing the cssText etc. seem to do anything and
styleSheetRule.style.removeExpression does not exist which would've
been the assumed way of doing it.
Does anyone know of a way? Setting the snork function to an empty
function does make performance reasonable, but with hundreds of these
classes on the page, it's still too slow - and I'm dealing with big
pages which is why parsing the DOM is too slow.
Jim.
IE has the ability to setExpressions on stylesheets so you can
calculate the value of the css property through script.
For various reasons I'm wanting to use a side-effect of this to attach
an event to every element of a class in a document (I'm including
content from a lot of large 3rd party content, and iterating over the
entire DOM searching for the classes and then attaching the event is
proving too slow, aswell as being too late post-load as the pages are
long and interaction would ideally occur before onload fires, it's an
embedded IE only solution.)
The solution I'm using is:
<URL: http://jibbering.com/2004/1/setExpression.html >
<style type="text/css">
.chicken {
color:green;
moomin:expression(snork(this));
}
</style>
<script type="text/jscript">
statusCount=0;
function snork(el) {
el.onclick=handler;
window.status=++statusCount;
}
function handler() {
alert("Hi!");
}
</script>
</head>
<body>
<p class="chicken">
A paragraph.
</p>
Obviously this is far from ideal as it means that the onclick handler
is attached everytime the css is evaluated (and this is often!) so I
need to remove the rule after attaching it. However I can't find a
way of doing this!
Changing the className of the objects to something else doesn't
achieve it, playing with the style or runtimeStyle of the object
doesn't, calling removeExpression on the elements style doesn't do
anything. So nothing on the element itself seems to achieve it.
Turning to the stylesheet, none of disabling the entire stylesheet,
removing the rule, changing the cssText etc. seem to do anything and
styleSheetRule.style.removeExpression does not exist which would've
been the assumed way of doing it.
Does anyone know of a way? Setting the snork function to an empty
function does make performance reasonable, but with hundreds of these
classes on the page, it's still too slow - and I'm dealing with big
pages which is why parsing the DOM is too slow.
Jim.