Simple JQuery-code but can it be optimized?

Simple JQuery-code but can it be optimized?

Hi,

I've got this in my <head>:

  1. <script type="text/javascript">
  2.       $jquery(document).ready(function(){
  3.              $jquery(".txt").hide();
  4.              $jquery(".map").hide();
  5.              $jquery("ul li a").click(function () {
  6.                    var divname= this.title;
  7.                    $jquery("."+divname).slideToggle("slow").siblings().hide("slow");
  8.             });
  9.       });
  10. </script>

And this as html formatting

  1. <ul class="knoppen">
  2.       <li><a title="txt" href="#">txt</a></li>
  3.       <li><a title="map" href="#">map</a></li>
  4. </ul>
  5. <div>
  6.       <p class="txt">Dummy text goes here</p>
  7.       <p class="map">Maps goes here</p>
  8. </div>

This works fine. Clicking on txt shows the dummy text, when txt is active and map is clicked, txt goes away. ok.

However I was wondering if things couldn't be more optimized? For example: I would like to see the 'titles' and even if possible the class txt and map.

Maybe it's not possible. But I always like cleaning coding. What's your opinion?

    • Topic Participants

    • joris