different div different target same function
Another newbie question ... loving the functionality of jquery, but still stumbling as I learn.
As I work on a complex navigational menu (complex as in lots of pages and categories) I am trying to figure out how to extract the numerical part of the triggering div's id and then attach it to events within the code, thus using one set of code for multiple menu pairs.
A snippet of code is below to show all the uses of the numerical part (using the jDiv plugin from Skyrocket Labs).
- var hide01 = false;
$("#nav1").hover(function(){
if (hide01) clearTimeout(hide01);
$("#hidden1").show();
$(this).addClass("active"); } ...... etc
In general someone hovers over the #nav1 div, which in turn reveals the #hidden1 div, same for nav2 & hidden2, nav3 & hidden3, etc. Right now I am simply duplicating the code for each pair, but it would be nice to figure out how to use variables and reduce code size.
I understand it is possible to perhaps get the numerical part using
- $(this.id).replace('nav','')
But haven't figured out how to attach it to the various values within the code (hide, #nav, #hidden)
My thanks in advance for any help