techiferous / tabulous

Easy tabbed navigation for Rails
Other
322 stars 35 forks source link

How to detect the tab or the subtab that the user clicked on #53

Closed svavantsa closed 9 years ago

svavantsa commented 9 years ago

I am using tabulous in a rails application that also uses bootstrap 3.0. On a particular page, it shows tabs and subtabs. I want to select the subtab that the user clicked on, to implement some special behavior. With the $(.subtabs).click method, I know that the user clicked on one of the subtabs. But this is actually referring to the parent div element that the subtab belongs to. How do I select the particular subtab that the user has clicked on?

See the screenshot below: image

The user may click on the Negotiations...sub tab or the Attachments subtab and I need to be able to detect the exact subtab that the user clicked on. Any suggestions?

techiferous commented 9 years ago

Unfortunately, tabulous' default HTML structure makes it difficult to do this, but not impossible. You can use jQuery to target a particular subtab by its position or by its href attribute. The other option is to write your own custom tabulous renderer that creates HTML that is easier to work with.

svavantsa commented 9 years ago

Wyatt, Yes there is a way, I found, without any further customization. See below:

$('.subtabs').click(function(){

tgtURL = $(".subtabs li a").attr("href") //Use this URL however you want })

If I have 3 subtabs, this gets me the URL of the subtab that I clicked on. I could have selected any a tag. But I needed it from the subtabs only. Hence this quest for this solution.

Thank you for developing this gem.

techiferous commented 9 years ago

Glad you found a solution!