Trying to Optimise jQuery function used in SharePoint Page
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');
精彩评论