• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Controlling element ids inside a table

 
sumit anand kumar
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Below is a section of my jsp code


Now i am able to execute the hyperlink on the first row, but not on the others. understandably the id is same for all the hyperlinks. how do i assign dynamic ids to the hyperlinks & tables such that i am able to toggle individual tables per hyperlinks
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, use the i variable in your loop? Or better yet, use a jQuery selector that finds the next table!

Eric
 
sumit anand kumar
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Um, use the i variable in your loop? Or better yet, use a jQuery selector that finds the next table!

Eric

Yeah Eric, I too thought so, but how do i change==> id="link1" to "link[i]" for each href and how do i tell jquery that every click of "link[i]" toggles "table[i]"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
id values are overused, in my opinion, and they are not even necessary here.

My advice is to ditch the ids.

Use a jQuery selector to apply the click handler to all the links in the tables with one statement, and use .closest() to find the parent table for toggling.

I also advise to stop using obsolete Java scriptlets in your JSPs. It's time to step out of 2002 and into 2012.
 
sumit anand kumar
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
I also advise to stop using obsolete Java scriptlets in your JSPs. It's time to step out of 2002 and into 2012.

Thanks Bear. I must say i am a bit rusty because its now quite a while i used javascripts. Also i am very exited to use jQuery and the hell lot of cool features it provides, not to mention it being easy.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic