jquery selectors - Simpler way of coding this -


On this page:

I have this jQuery, but it seems a little curved.

  & lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ("p"). Hide (); $ ("# lastfmrecords") Hide (); $ ("h2.btn1 a") Click (function () ($ ("Ol.btn1> *") Toggle (400);}); $ ("h2.btn2 a"). Click (function () {$ ("ol.btn2> *" Click toggle (400) $ ("H2.btn3 a"). (Function () {$ ("ol.btn3 & gt; *") Toggle (400);}); $ ("h2.btn4 A "). Click (function () ($ (" ol.btn4> * ") Toggle (400);}); $ (" h2.btn5 a "). Click (function () {$ ("Ol.btn5> *") $ ("H2.btn6 a"). (Function () {$ ("ol.btn6 & gt; *") Toggle (400);}); $ ("H2.btn7 one"). Click (function () {$ ("ol.btn7> *") Toggle (400);})}}); & lt; / script & gt; & Lt ; H2 class = "btn5" & gt; & lt; a hr Ef = "#" & gt; Facebook Books & lt; / a & gt; & lt; / h2 & gt; & lt; ol class = "btn5"> 

FreeConomics, Bad Science , A brief history of almost everything, 100 years of solitude, on Cheshib Beach

Then I have 7 names There is a list of those names, no. 5 above (BTN1 - BTN7) that toggle when I match the heading H2, which matches. All the work is fine, but is there any way of compacting jQuery?

For a the loop looks like a clear solution.

  $ (document) .ready (function () {$ ('ol') .for Hide (); (var i = 1; i & lt; = 7; ++ i ) {$ ('H2.btn' + i + 'a'). Click (function () {$ ('ol.btn' + i + '& gt; *'). Toggle (400);}); }});    

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -