• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jQuery: How to change table row background color when we do sorting?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've a table rows with alternate background colors (while and cyan, even and odd respectively) , but when I do sorting with Jquery those rows colors are not changing according to orders.


From the above "alt" class also doesn't help to me. Can anyone help on this?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, "alt" is a horrible name. Use something more descriptive.

Think about it for a minute:
  • You have some rows that have the alt class name.
  • Then you rearrange the rows.
  • And then you add alt to every other row in the rearrangement.


  • Now which rows have the class name. Is it just the odd rows? Really?
     
    author
    Posts: 297
    5
    Android Firefox Browser Fedora
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Why are you doing it with jQuery anyway? Every current browser can do this with CSS:

    Do you specifically need IE8 support? Write some code in a conditional comment to handle IE8 and before, support all the other browsers the easy way.
     
    Bear Bibeault
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Doing it with CSS completely solves the problem.

    But do you understand why the original problem exists?

    Hint: open the JavaScript debugger and look at the elements of the DOM after the sort. See which ones now have the alt class.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic