jquery - How to change text in a html table cell based on value in another cell -


i have html table tens of columns , hundreds of rows. want change value of 1 table cell (td) based on value of column. (i need 3 pairs of columns). since have no control on data source, order of columns may vary in browsers. steps i've taken:

for(i=0;i<3;i++){     for(j=0;j<2;j++){         if(!!(jq("div[displayname='"+updateviewerfields[i][j]+"']"))){             updateviewer[i][j]=(jq(this).find(jq("div[displayname='"+updateviewerfields[i][j]+"']")).parent().index())+1;     }}} 

this stores index location of 3 fields in array - 'updateviewer'. names of 3 fields coming in 'updateviewerfields'.

var updateviewerfields=[["phase 1","phase 1 - comments"],["phase 2","phase 2 - comments"],["phase 3","phase 3 - comments"]]; var updateviewer=[[0,0],[0,0],[0,0]]; 

now, iterate through each row applying formatting:

       jq(this).find("tr").each(function(){             //update data per matrix             for(i=0;i<3;i++){                if(0!=updateviewer[i][0]){                 var currentphaseelement= jq(this).find(jq('td:nth-child('+updateviewer[i][0]+')'));               jq(currentphaseelement).attr('title',jq(this).find(jq('td:nth-child('+updateviewer[i][1]+')')).html()); //other stuff     }     }} 

the code runs without error.however, code slow in ie. warning when using ie -

'a script on page causing internet explorer run slowly. if continues run, computer may become unresponsive. want abort script?' 

however, same code runs smoothly in chrome. how can improve code achieve same effect faster response times in ie? ps> please suggest changes code only.

here fiddle representation: http://jsfiddle.net/qzs2g/7/

update: jq in code here variable run jquery in noconflict mode.

var jq=jquery.noconflict();  

the fiddle uses ubiquitous $ sign

here of optimizations found in 2 days:

you can read more in article. http://www.artzstudio.com/2009/04/jquery-performance-rules/

the steps mentioned here helped me reduce load times of pages significantly. hope these practices other html/javascript developers well.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -