Two elements should never have the same ID - make sure the links and
the paragraphs do NOT have the same ID. Some people use the 'rel' tag
for this sort of thing. Use the class attribute to denote objects that
should be grouped (ie, the paragraphs you want to hide) Eg:

<ul id="myList">
   <li><a rel="001" href="#">001</a></li>
   <li><a rel="002" href="#">002</a></li>
   <li><a rel="003" href="#">003</a></li>
</ul>

<p id="001" class="myItems"></p>
<p id="002" class="myItems"></p>
<p id="003" class="myItems"></p>

In you jQuery, you can then do this:

$(document).ready(function() {

   $('#myList li a').click(function() {

      var t = $(this).attr('rel');
      $('p.myItems').hide();
      $('#'+t).show('slow');

  });

});

Hope this helps - and don't forget to read the documentation if you
get stuck:

http://docs.jquery.com



On Jun 2, 7:20 pm, jgarcia <[EMAIL PROTECTED]> wrote:
> i've a dinamic menu
>
> <ul>
> <li><a id="001" href="#">001</a></li>
> <li><a id="002" href="#">001</a></li>
> <li><a id="003" href="#">001</a></li>
> </ul>
>
> this menu <ul> is dynamic, ie, is automatically generated from a
> database, therefore I will not know many elements i'll have in the
> future or what identifiers they have.
>
> Moreover, i have some <p>, one for each <a> in the <ul>
>
> <p id="001"></p>
> <p id="002"></p>
> <p id="003"></p>
>
> If somebody do click in  <a id=001>  all <p> must be hide, but the <p
> id=001> must be show
>
> i've writed this code in jquery for the case "001"  and is run
> perfect, but a need do it general for all <a> but without
> those elements will have a priori
>
> <script type="text/javascript">
> $(document).ready(function (){
>
>         $("#content p").toggle();
>
>         $("#menu ul li a#001").click
>                 (
>                 function showhide()
>                         { $("#content p#001").toggle("slow"); }
>                 )
>         }
>         )
> </script>
>
> understand me?
>
> thanks in advance

Reply via email to