- From: Andrew Fedoniouk <news@terrainformatica.com>
- Date: Thu, 24 Jul 2008 00:25:16 -0700
- To: Francois Remy <fremycompany_pub@yahoo.fr>
- CC: Boris Zbarsky <bzbarsky@MIT.EDU>, www-style list <www-style@w3.org>
Francois Remy wrote:
>
> Sorry but it's not true... If you talk about the fact about the fact I
> abonnate myself on mouseover events, please give my a solution that can
> do I receive a JScript event any time something change for the specified
> element ? It's not possible in JScript. So, yes, I must abonnate myself
> on the event manually. But there's no other possibility.... Yes, there's
> setInterval, but it's not really the good solution.
>
> You can change it to (where ... are respectively the "before-selector
> selector" and "child-selector" in my sample).
> Then, you can add a new css rule replace :with.... with ".-with-child-n".
>
> var cwc_count = 0;
> function createCSSWithChildRule(beforeSelector, childSelector,
> afterSelector, rule) {
> var count = cws_count; cws_count=cws_count+1;
>
> var sheet = document.createStyleSheet();
> sheet.cssText = beforeSelector + ".-with-child-"+count + " "
> + afterSelector + "{" + rule + "}";
>
> function update() {
> var divs = document.querySelectorAll(beforeSelector);
> var l=divs.length;
> for (var i=0; i<l; i++) {
> if (divs[i].querySelector(childSelector)) {
> divs[i].className="-with-child-"+count;
> } else {
> divs[i].className="";
> }
> }
> }
>
> /* I don't have better solution if we must generalize in
> JScript */
> setInterval(update, 500);
> }
>
> createCSSWithChildRule("body > div", "a:href", "a", "background:
> yellow")
>
>
> Fremy
>
>
/* I don't have better solution if we must generalize in JScript */
setInterval(update, 500);
(As far as I understand you think that there is a better
solution, right?)
Your function update() {} has worst case complexity O(n*n).
You can *easily* hit the point when it will take more than 500ms
to execute. So UA will be busy crunching selectors most of the time.
Cheers.
--
Andrew Fedoniouk.
http://terrainformatica.com
Received on Thursday, 24 July 2008 07:25:51 UTC