Introduction
In this article, we will learn about jQuery Interaction. jQuery offers 5 kinds of interactions. All are mouse-based and can be used in combination to provide easy interaction for users. This article will cover all the five jQuery UI interactions and it'll use the source file of the Part 1 article. So if you haven't had a look at Part 1 then you have two options.
The first is you can continue with this article or you can have a look at Part 1.
A quick overview of Part 1
In Part 1 we learned how to add a widget on any HTML element. In brief it is like:
$(element_to_target).widget_name({List_of_options});
If we dismantle this line of code then we have the following to learn:
- $ - It is a valid JavaScript identifier or variable name and it's a shorthand notation for writing jQuery. For instance, the following two code samples represent the same thing.
code1:jQuery('.test').tooltip();code2:$('.test').tooltip();
-
$(element_to_target) - Here the mystery is in shorthand. If we replace the $ with jQuery then it will look like this: jQuery('element_to_target'). Oh, guess what it is! It looks like nothing but a function call where "element_to_target" is a parameter passed to a function. In a nutshell, it represents a function call that wraps the element_to_target into a jQuery object.
-
.widget_name() - It is used for setting a particular widget on that object.
For examples and more details, you can check Part 1 of this article.
Working with jQuery Interactions
Draggable
-
To add this effect just add this line off code to your JS file after "$('#login').tooltip({});":$('#dropme').draggable({});Here this line adds the draggable interaction to the accordion widget. Please note that excessive use of this interaction may lead to the clustering of elements. So use it wisely.
-
Now add this in your HTML within the body tag but as the last element (it is not necessary but helps in maintaining the page structure).<div id='dropme' style='width:100px;height:10px;color:red;'>Can you drop me on Green.</div>

Droppable
-
To add this effect you need to add this code to your HTML file:
- <div id='plsCome' style='width:100px;height:100px;background-color:green;'></div>
- This basically adds a new div the to page that we will be our drop target.
-
Now add this line of code in your JS file to add droppable interaction on the newly created Div:
- $("#plsCome").droppable({
- drop: function () {
- $(this).html("Thanks for your help!");
- }
- });
This time I added one option, "show", to the option braces to make the effect visible. This function will be executed when the element is dropped on it. The ".html()" sets the content of the div.




sonal kumarPosted Nov 28, 2013, 2:41 PM
thank u.....its very easy to learn jQuery UI.