aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Controlling element ids inside a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Controlling element ids inside a table" Watch "Controlling element ids inside a table" New topic
Author

Controlling element ids inside a table

sumit anand kumar
Ranch Hand

Joined: Apr 28, 2010
Posts: 83


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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Apr 28, 2010
Posts: 83
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

Joined: Jan 10, 2002
Posts: 60975
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sumit anand kumar
Ranch Hand

Joined: Apr 28, 2010
Posts: 83
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Controlling element ids inside a table