开发者

Trying to Optimise jQuery function used in SharePoint Page

开发者 https://www.devze.com 2023-01-26 18:16 出处:网络
I\'m attempting to optimise the jQuery code below, it iterates through all the TD tags on the page searching for any that has \"eventClassXXXXXX\" as its class attribute (where \"XXXX\" could be numer

I'm attempting to optimise the jQuery code below, it iterates through all the TD tags on the page searching for any that has "eventClassXXXXXX" as its class attribute (where "XXXX" could be numeric or alphabetic).

$(document).ready(function () {
    $("td").each(function () {
        $(this).attr("class", this.className.replace(/eventClass/gi, 'eventClass '));
    });
});

so it would change

"<TD class='eventClass12345678'>" 

to

"<TD class='eventClass'>

The problem 开发者_开发百科is it takes ages to run on a sharepoint page (right-click on a sharepoint page and click view source to see why). The reason I have to do this is becauyse there is a third party webpart on the page that I'm attempting to restyle (wasn't supplied as open-source)

Let me know if you have any ideas on optimizing this or another way round. Thanks

Thanks


Maybe something like this would be faster:

$('td[class^=eventClass]').attr('class','eventClass');

If there's some sort of container element available (perhaps the table), this would be much better:

$('#container').find('td[class^=eventClass]').attr('class','eventClass');
0

精彩评论

暂无评论...
验证码 换一张
取 消