Click here to Skip to main content
13,139,569 members (54,094 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

5K views
6 bookmarked
Posted 14 Oct 2014
MIT

Some Basics of jQuery

, 14 Oct 2014
Rate this:
Please Sign up or sign in to vote.
Some basics of jQuery

Well, I guess our website is now good to go for uploading and deleting the files from the server. But that doesn’t look that much cool, is it? 

Adding Some Pro Features

So let's start adding some professional features to it! For example, let's try to add some names or some more content to the page or let's just add some cool styles to the page like showing the form or hiding the form. Should we? Okay then...

First Step

First step we will do will be to go to this site: http://jquery.com/ and download the latest version of jQuery or even download the recommend one. Don’t like to read and do all that stuff? It's ok! Try to add this link in the head section of your website:

<script href="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Let's Begin the Coding

Ok, so I guess you are now having your website connected to the powerful JavaScript Library jQuery. Try to understand, that jQuery itself is a JS. It is not something else, it in the code behind the scenes that makes use of the pure JS and lets you easily handle the events on the browser.

Understanding the Methods

Now let's start understanding how we can handle the events on an elements using jQuery. 

In basic js, you wrote the stuff as:

<element onclick="functionname"></element>
// such as
<button onclick="submitform"></button>

Now to handle the event, you did something like:

<script>
  function submitform() {
    // remember functions are methods so you must use
    // (). You can pass parameters through this too. 
    // and here you submitted the form or validated it 
  }
</script>

But jQuery makes it simpler and easier. How? Look for yourself:

<script>
   // now lets use the input of text as the name
   // and the submit as the button to execute the change
   $('#submit').click(function () {
     var name = $('#name').val(); // val is a method; thus ()
     alert(name); // alert the name for the user..
   });
</script>

<!-- body elements are as under -->

<input type="text" name="name" id="name" />
<input type="submit" value="Submit" id="submit" />

The above code will first take the user’s input for the name and then it will show the name as an alert when the user will click submit. You can see the code working by the usage of the id (#). 

Now let's understand what other stuff jQuery can do for us.

Hiding and Showing the Content

If we want to hide the content, or show a content sometime when we want it to be visible to the user such as a popup; customized one. Then we can make a use of jQuery and toggle it using:

<button></button>

// jQuery for this will be
$('button').hide();
$('button').show();
$('button').toggle();

Now, you might want to ask what is toggle? Toggle means if the element is hidden, it will show it, if it is visible it will hide it! It's a round-off for the hide/show methods. You can also use the speed for the process in milliseconds. For example, if you write 1000 in the parenthesis, then the process will take 1 second and will hide or show in a perfect manner for the user to understand that something is coming up for me to fill in or view.

Changing CSS Properties for Elements

There are some other uses of jQuery too, such as changing the CSS for the current element. We can do that using...

$('element').css({
  // write the properties here such as
  "width": "100px",
  "height": "50px"
});

...and so on. jQuery is an endless library of JS. You will find each and everything and will be able to edit and customize the page effects using just jQuery.

Good luck!

License

This article, along with any associated source code and files, is licensed under The MIT License

Share

About the Author

Afzaal Ahmad Zeeshan
Student
Pakistan Pakistan
Computer programmer, author, student, in a relationship and not available!

You may also be interested in...

Comments and Discussions

 
GeneralMy Vote 5 Pin
Shemeemsha29-Oct-14 20:12
memberShemeemsha29-Oct-14 20:12 
GeneralRe: My Vote 5 Pin
Afzaal Ahmad Zeeshan30-Oct-14 4:23
professionalAfzaal Ahmad Zeeshan30-Oct-14 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 14 Oct 2014
Article Copyright 2014 by Afzaal Ahmad Zeeshan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid