• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Madhav Kanneganti
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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?
     
    Rob Crowther
    author
    Ranch Hand
    Posts: 297
    5
    Android Fedora Firefox Browser
    • Likes 1
    • Mark post as helpful
    • send pies
    • 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
    Author and ninkuma
    Marshal
    Pie
    Posts: 64620
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic