javascript - Go to table row where color equals -


i have table need automatically scroll highlighted row, code thought of:

            var container = $('#table_id'),         scrollto = $("table tr background-color:contains('#ffcc66')");         container.scrolltop(             scrollto.offset().top - container.offset().top + container.scrolltop()         ); 

where "#ffcc66" background-color of row highlighting

this returns error:

error: unable property 'top' of undefined or null reference 

why not working?

i think should add class highlighted element , do:

var container = $('#table_id'),     scrollto = $("table tr.highlighted");  container.length && container.scrolltop(         scrollto.offset().top - container.offset().top + container.scrolltop() ); 

or way you're doing it, should work:

var container = $('#table_id'),     scrollto = $("table tr").filter(function() {         return $(this).css('background-color').tolowercase() == '#ffcc66';     });  container.length && container.scrolltop(         scrollto.offset().top - container.offset().top + container.scrolltop() ); 

Comments