Note that there are some explanatory texts on larger screens.

plurals
  1. POBeginner Javascript: jQuery 'toggle' problem
    primarykey
    data
    text
    <p>HI All,</p> <p>I'm a veritable JS beginner and thus I've been using some simple bits of jQuery to help give me the effects I want. All has been going well until I tried to implement a jQuery toggle effect. I want the code to apply to multiple elements and so I'm trying to slim it down and make it generic rather than writing a line for each toggle tab.</p> <p>I just can't seem to get it to work!</p> <p><strong>Head w/ javascript:</strong></p> <pre><code>&lt;head&gt; &lt;title&gt;My Title&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css" /&gt; &lt;link rel="stylesheet" type="text/css" href="style.css" /&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#content div[id^=toggle]').hide(); $('[class^=info]').click(function() { var x = $(this).attr("idName"); $('#toggle_' + x).toggle(); return false; }); }); &lt;/script&gt; &lt;/head&gt; </code></pre> <p>Body:</p> <pre><code>&lt;div id="content"&gt; &lt;div class="info_tab" id="info_grover"&gt; &lt;img src="images/pgrover_120x137.jpg" alt="Philip Grover" /&gt; &lt;h1&gt;Philip Grover&lt;/h1&gt;&lt;br /&gt; &lt;p&gt;Info about Philip Grover&lt;/p&gt; &lt;/div&gt; &lt;div id="toggle_info_grover"&gt; &lt;/div&gt; &lt;div class="info_tab" id="info_lewis"&gt; &lt;img src="images/rlewis_120x137.jpg" alt="Roy Lewis" /&gt; &lt;h1&gt;Roy Lewis&lt;/h1&gt;&lt;br /&gt; &lt;p&gt;Info about Roy Lewis&lt;/p&gt; &lt;/div&gt; &lt;div id="toggle_info_lewis"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I know the answer is probably extremely simple and I suspect it has something to do with my usage of the "this" keyword but after an hour of searching I can't seem to work it out for my specific scenario. I'd really appreciate any advice.</p> <p>Thanks in advance,</p> <p>Rich</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload