Beginner Javascript: jQuery 'toggle' problem -


hi all,

i'm veritable js beginner , i've been using simple bits of jquery give me effects want. has been going until tried implement jquery toggle effect. want code apply multiple elements , i'm trying slim down , make generic rather writing line each toggle tab.

i can't seem work!

head w/ javascript:

<head> <title>my title</title> <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css" /> <link rel="stylesheet" type="text/css" href="style.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>  <script type="text/javascript"> $(document).ready(function() {     $('#content div[id^=toggle]').hide();     $('[class^=info]').click(function() {         var x = $(this).attr("idname");         $('#toggle_' + x).toggle();         return false;         });     }); </script>  </head> 

body:

<div id="content">     <div class="info_tab" id="info_grover">         <img src="images/pgrover_120x137.jpg" alt="philip grover" />         <h1>philip grover</h1><br />         <p>info philip grover</p>     </div>     <div id="toggle_info_grover">     </div>     <div class="info_tab" id="info_lewis">         <img src="images/rlewis_120x137.jpg" alt="roy lewis" />         <h1>roy lewis</h1><br />         <p>info roy lewis</p>     </div>     <div id="toggle_info_lewis">     </div> </div> 

i know answer extremely simple , suspect has usage of "this" keyword after hour of searching can't seem work out specific scenario. i'd appreciate advice.

thanks in advance,

rich

your code looking attribute called "idname", , yet none of html elements have attribute. think want "id".

    var x = $(this).attr("id"); 

or, more simply,

    var x = this.id; 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -