Solved

Jquery plugin authoring

Posted on 2010-08-24
6
355 Views
Last Modified: 2013-11-11
Hi,
I need to reuse the same bit of code numerous times, so i'm figuring plugins for jquery are probably the way to go. The examples though seem to be quite complex and I cant get my head around them.
Can anyone point me in the right direction please?
Here is the code I am going to use for the plugin, I just need to know how to modify it as a plugin:
<script type="text/javascript">
          $('.tabs').find('div:first').siblings('div').hide();
          $('.tabs > ul > li >a').click(function(e){
              container=$(this).parent().parent().parent();
              $(this).parent().addClass('selected').siblings().removeClass('selected');
              $('.'+$(this).attr('rel'),container).show().siblings('div').hide();//Show the div with the content in
              e.preventDefault();
          });
      </script>

Open in new window


Which will be used in conjunction with the following markup:

 <div class="tabs">
          <ul>
              <li><a href="#" rel="tab1">Tab1</a></li>
              <li><a href="#" rel="tab2">Tab2</a></li>
              <li><a href="#" rel="tab3">Tab3</a></li>
          </ul>
          <div class="tab1">Tab 1 content</div>
          <div class="tab2">Tab 2 content</div>
          <div class="tab3">Tab 3 content</div> 
      </div>

Open in new window

0
Comment
Question by:jdav357
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33511830
Could you please rephrase the question a little, as i couldn't understand the requirement?
Thanks
0
 
LVL 2

Author Comment

by:jdav357
ID: 33511886
With my javascript I have attached, I need to change it to a plugin, so that I can just add a class or id of tabbed for example to an element and it will use my function above!
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33511902
please mention what your code is trying to do.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Expert Comment

by:SRigney
ID: 33511925
This tutorial seems to be an easier one to understand.

http://www.queness.com/post/112/a-really-simple-jquery-plugin-tutorial
0
 
LVL 2

Author Comment

by:jdav357
ID: 33511927
[code]
<script type="text/javascript">
          $('.tabs').find('div:first').siblings('div').hide();
          $('.tabs > ul > li >a').click(function(e){
              container=$(this).parent().parent().parent();
              $(this).parent().addClass('selected').siblings().removeClass('selected');
              $('.'+$(this).attr('rel'),container).show().siblings('div').hide();//Show the div with the content in
              e.preventDefault();
          });
      </script>
[/code]
This is my code that I am trying to convert in to a plugin. It is for a special kind of tabs that I require. Thanks for your help.
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 33512037
i think you code is already in shape, just add this
<<# (function($){>>  in the beginning
and <<})(jQuery);  >> in the end

http://net.tutsplus.com/articles/news/learn-how-to-create-a-jquery-plugin/
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now