Solved

Jquery plugin authoring

Posted on 2010-08-24
6
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…
Suggested Courses

630 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