2

I am new to jQuery world, and only today started using sublime text 2. Therefore, I am not aware of what packages I have to download and how to download. So, I would kindly request if anyone know how do I add jQuery to use it in my sublime text 2 editor. It will be great if you can give me a step by step instructions, like I said I am new to this. Also, how to get list of selections for jQuery.

Any help would be greatly appreciate it. Thanks :]

user123
  • 87
  • 3
  • 11

2 Answers2

3

jQuery is a JS library. To use it you need to include it in your document like:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Than you'll be able to manipulate your DOM elements/events doing crazy stuff like this:

<script>
    $(function(){
        $('body').prepend('HELLO EVERYONE!');
    });
</script>

or like

this demo

To help you in your work Sublime has a possibility to easily include that jQuery library by creating a shortcut snippet, I'll show you how:

Tools > New Snippet...

<snippet>
<content><![CDATA[
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
]]></content>
<tabTrigger>jquery</tabTrigger> <!-- the text that using [Tab] will paste the snippet -->
</snippet>

File > Save As...
(Under Documents And Settings/yourUserName/Application Data/Sublime Text 2/Packages/User/ )

jquery.sublime-snippet

Restart Sublime type jquery + hit your TAB key and the jQuery library snippet will be included in your document.

The same way you can create your own snippets that you use over and over for example like

$(function(){

});

var intv = setInterval(function(){

}, 1000 );
Roko C. Buljan
  • 164,703
  • 32
  • 260
  • 278
  • Can you please explain this snippet bussiness? Like I said, I am a beginner I have no knowledge. – user123 Mar 07 '13 at 00:44
  • Thanks for your time. Although, I have found video which shows me how to download the jQuery bundle. I don't know if I was clear or not. But for the effort in explaining, thumbs up :) – user123 Mar 08 '13 at 21:38
  • I would like to keep the files seperate. So if i create a jQuery file, and link it to html file. What do I have to add inside the jQuery file? – user123 Mar 08 '13 at 23:21
  • @user123 You see the demo jsBin I added into my answer? Click on the JsBin logo and click "Download". After you download the .html file you'll see how it all works. The jQuery library is included from Google APIs, than if you want to have a separate file for your functions, create a functions.js file and link to it. In that JS file all you need to do is to wrap your code into *DOM ready function*. – Roko C. Buljan Mar 10 '13 at 12:16
  • Hey, Thanks a lot. Really appreciate your help :) – user123 Mar 10 '13 at 19:39
2

Sublime Text 2 is just an editor, you don't need to use the packages, snippets, etc. to use jQuery. In the HTML file where you want to use jQuery, you need to add a script tag that points to where the jQuery framework lives (this can either be a local path to where you placed jQuery, or a url of where jQuery resides on the internet).

For example:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
    jQuery(function(){
        // your code goes here, you can use jQuery at this point
    });
</script>

As for a list of "selections" that really depends on the HTML markup you use. At this point, I can only recommend you read the jQuery documentation. Here's a link to their learning center: http://learn.jquery.com/

Alex Heyd
  • 1,323
  • 1
  • 10
  • 17
  • I would like to keep the files seperate. So if i create a jQuery file, and link it to html file. What do I have to add inside the jQuery file? – user123 Mar 08 '13 at 23:20