Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Removing row from table

 
Sowmiya Selvamani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First i am changing the background color of a row in a table on mouse click. Then If I press remove button i need to remove all the rows which has background color. can anyone help me to do this?
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe in jQuery it would look something like...



Check into it. Its very nice

www.jquery.com

thanks
Bryce
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loop through all of the table rows and remove the class.

var rows = document.getElementById("yorTableId").getElementsByTagName("tr");
for(var i=0;i<rows.length;i++){
rows[i].style.className = "normal";
}

Eric
[ January 21, 2008: Message edited by: Eric Pascarello ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Small correction to jQuery example:
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first idea was to code it as you have coded it. I use Visual jQuery 1.1 to look at the methods and how they are used. http://visualjquery.com/1.1.2.html

Now, I know that 1.2.2 is out but this should still apply. If you look under DOM -> Manipulation -> remove the example seems to show the way I coded it. Is it wrong on there? Is there a better quick reference out there than that site?

Thanks Bryce
 
Yehuda Katz
Author
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Bear said'll work great! Keep in mind, however, that animating table changes is still quite a bit of black magic, because table rows can't smoothly and reliably change size. If you want to change the size of a table row, you'll probably need to wrap all of the TRs in individual DIVs, give the DIVs overflow: hidden, and then shrink the divs.

something like

where you have the following in your CSS:

[ January 21, 2008: Message edited by: Yehuda Katz ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I should have said "alternative" rather than correction. My bad. There's no need to select all the tr's and then filter them rather than selecting only the target ones in the first place.
[ January 21, 2008: Message edited by: Bear Bibeault ]
 
Yehuda Katz
Author
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My comment above, just to be clear, only applies to *animating* table cells with slideUp or slideDown. That's because table cells can't get overflow: hidden and so can't animate smoothly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic