Hierarchy selector in jQuery

Basic jQuery selectors work the same as CSS selectors:

$('p');
Selects all the <p> elements in your page
$('*');
Selects all elements on the page
$('.status');
Selects all elements with the class status
$('#header');
Selects the element with the id header
[Note]Note
You should not use the same id for more than one element. If you do so and if you perform a selection by id, only the first matched element in the DOM will be returned
$('p, li, .status, #nav');
Selects all <p> and <li> elements, all elements with the status class, and the element with the id nav.
----------------------------------------------------------------------------------

jQuery hierarchical selectors also work the same as CSS selectors:

$('#footer span');
Selects the <span> elements that are descendants of the element with the id footer.
$('ul > li');
Selects the <li> elements that are immediate children of <ul> elements.
$('h2 + p');
Selects the <p> elements that are immediately preceded by an <h2> element.
$('h2 ~ p');
Selects all <p> elements following an <h2> element that have the same parent as the <h2> element. ----------------------------------------------------------------------------------
Another powerful selection type is selection by attribute:
$('a[href]');
Selects all <a> elements that have an href attribute.
$('a[href="http://mrkn.co/f/271"]');
Selects all <a> elements whose href attribute exactly matches "http://mrkn.co/f/271".
$('a[href*="goo.gl"]');
Selects all <a> elements whose href attribute contains "goo.gl". For example, this would match:
<a href="http://goo.gl/DeSyV" class="url">Interesting link</a>
$('a[href^="http://bit.ly"]');
Selects all <a> elements whose href attribute starts with "http://bit.ly". For example, this would match both of these elements:
<a href="http://bit.ly/eU3ccR" class="url">One link</a>
<a href="http://bit.ly/jqcon11SF" class="url">Another link</a>
$('a[href$=".pdf"]');
Selects all <a> elements whose href attribute ends with ".pdf". For example:
<a href="http://mrkn.co/docs/info.pdf" class="url">Download PDF version</a>
$('p[lang|="en"]');
Selects all <p> elements whose lang attribute matches either "en" or "en-\*", where * can be anything.
[Note]Note
A detailed explanation on selection by attribute can be found at the following URL: http://api.jquery.com/category/selectors/attribute-selectors/

----------------------------------------------------------------------------------

jQuery also comes with useful selectors related to forms.

$(':button'); , $(':checkbox'); , $(':file'); , $(':image'); , $(':password'); , $(':radio'); , $(':reset'); , $(':submit'); , $(':text');
Selects all <input> elements of the specified type.
$(':input');
Selects all form elements, including <textarea> and <select> elements.
$(':checked');
Selects all checkbox and radio elements that are checked.
$(':selected');
For <option> elements, returns the selected option(s).
$(':disabled'); , $(':enabled');
Selects all disabled/enabled form elements.
[Note]Note
It’s recommended to precede these selectors with a tag name or some other selector; otherwise, the universal selector (*) is implied (e.g., $(":checkbox") implies $("*:checkbox")).
The following will serve as an example to demonstrate form selectors:
<form name="foodieform">
  <fieldset>
    <legend>Search a recipe:</legend>
    <label for="txt_recipe_name">Recipe name:</label>
    <input type="text" name="txt_recipe_name" id="txt_recipe_name" />
    <label for="meal_type">Type of meal:</label>
    <select id="meal_type" name="meal_type">
      <option value="Apetizer" selected>Apetizer</option>
      <option value="Entree">Entree</option>
      <option value="Drinks">Drinks</option>
      <option value="Desert">Desert</option>
    </select>
  </fieldset>
  <fieldset>
    <legend>Choose a type of food</legend>
    <input type="checkbox" name="food_type" value="French" checked>French</input>
    <input type="checkbox" name="food_type" value="Italian">Italian</input>
    <input type="checkbox" name="food_type" value="Mexican">Mexican</input>
    <input type="checkbox" name="food_type" value="Chinese">Chinese</input>
  </fieldset>
  <fieldset>
    <legend>Skills required</legend>
    <input type="radio" name="food_skills" value="1"/>Easy
    <input type="radio" name="food_skills" value="2"/>Medium
    <input type="radio" name="food_skills" value="3" checked/>Hard<br/>
  </fieldset>
  <input type="button" name="form-button" id="form-button" value="search"/>
  <input type="reset" name="form-reset" id="form-reset"/>
</form>
  • $(':checked'); would select:
    <input type="checkbox" name="food_type" value="French" checked>French</input>
    <input type="radio" name="food_skills" value="3" checked/>Hard<br/>
  • $(':radio'); would select:
    <input type=​"radio" name=​"food_skills" value=​"1">
    <input type=​"radio" name=​"food_skills" value=​"2">​
    <input type=​"radio" name=​"food_skills" value=​"3" checked>
  • $(':reset');:: Selects reset elements. In this case:
    <input type=​"reset" name=​"form-reset" id=​"form-reset">
  • $(':selected'); would select:
    <option value=​"Appetizer" selected>​Appetizer​</option>
  • $(':text'); would select:
    <input type=​"text" name=​"txt_recipe_name" id=​"txt_recipe_name">
[Note]Note
More information on form selectors is available here ⇒ http://api.jquery.com/category/selectors/form-selectors/

Sliding effect using jQuery

if you need any functionality like sliding image or menu , then you can use below code :

$('.menu-ul1').hide();

$('.menu-li1').toggle(function(){
   $(this).next('.menu-ul1').slideDown();
},function(){
   $(this).next('.menu-ul1').slideUp();
});

Fadding effect in jQuery

Guys

When you have requirement for giving fadding effect in your application , you can use below code :

$('.menu-ul1').hide();

$('.menu-li1').toggle(function(){
   $(this).next('.menu-ul1').fadeIn();
},function(){
   $(this).next('.menu-ul1').fadeOut();
});

Hide and show element

Hi everyone,

Use below code for hiding and showing elements :

$('.menu-ul1').hide();

$('.menu-li1').toggle(function(){
   $(this).next('.menu-ul1').show();
},function(){
   $(this).next('.menu-ul1').hide();
});

Effect Methods using jQuery

Effect Methods

There are a number of ways to easily add animation effects, many of which simply extend existing jQuery methods.

Basic Effect Transition

The simplest way to apply an animation effect is to call the effect() method on any DOM element and specify the animation type, options, speed and callbacks as needed. If you need to couple an animation with a hide, show or toggle effect, see the visibility transitions in the next section.
  • Effect - Direct way to apply an animation to any element

Visibility Transitions

These effect extend the base class API to bring visual transitions to the standard hide, show and toggle visibility functions in jQuery. All the standard animation types are supported.
  • Show - As an element is being shown, animate it's entrance
  • Hide - As an element is being hidden, animate it's exit
  • Toggle - As an element is being toggled between show or hide states, animate the transition

Color Transitions

The jQuery UI effects core extends the animate function to be able to animate colors as well. These transitions can animate the background and border colors and accept colors specified in hex, rgb and color names. This is used extensively by the class transition effects in the next section.
  • Animate - Animate background and border colors

Class Transitions

The jQuery UI effects core extends the base class API to be able to animate between classes. This is a very powerful way script complex animations because these effects analyze the differences between the style attributes of the classes and automatically builds parallel animations to transform between the various style attributes that are different. Any style attribute that contains a numeric value will be animated, from hex colors to dimensions, padding, margins, border thickness, positioning, font size, line-height and more will automatically animate.
  • addClass - Adds a class to elements with an animated transition between the states.
  • removeClass - Removes a class to elements with an animated transition between the states.
  • toggleClass - Adds a class if it is not present, and removes the class if it is present with an animated transition.
  • switchClass - Switches between one class and another with an animated transition.

Advanced Easing

The excellent jQuery easing plugin porting Robert Penners advanced easing functions to jQuery has been included into effects.core.js.

Create tabs using jQuery tab plugin

Hi everyone,

You can use below code to generate tabs using jQuery tabs plugin :

<script>
 $(function() {
  $( "#tabs" ).tabs();
 });
 </script>



<div class="demo">

<div id="tabs">
 <ul>
  <li><a href="#tabs-1">Nunc tincidunt</a></li>
  <li><a href="#tabs-2">Proin dolor</a></li>
  <li><a href="#tabs-3">Aenean lacinia</a></li>
 </ul>
 <div id="tabs-1">
  <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, </p>
 </div>
 <div id="tabs-2">
  <p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante,</p>
 </div>
 <div id="tabs-3">
  <p>Mauris eleifend est et turpis. Duis id erat.</p>
  <p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna.</p>
 </div>
</div>

</div><!-- End demo -->



<div style="display: none;" class="demo-description">
<p>Click tabs to swap between content that is broken into logical sections.</p>
</div><!-- End demo-description -->
 
 
Post your comment if you find any difficulties to develop tabs. 

Create slider using jQuery

you can use below code to generate slider using jQuery :

<style>
 #demo-frame > div.demo { padding: 10px !important; }
 </style>
 <script>
 $(function() {
  $( "#slider" ).slider();
 });
 </script>



<div class="demo">

<div id="slider"></div>

</div><!-- End demo -->



<div style="display: none;" class="demo-description">
<p>The basic slider </p>
</div><!-- End demo-description -->