• Now Online : 24
  • admin@codemyne.net

Introduction

jQuery-CSS Universal Selector

Description:

The universal selector selects all the elements available in the document. Here is the description of all the parameters used by this selector. Like any other jQuery selector, this selector also returns an array filled with the found elements.

Syntax: Here is the simple syntax to use this selector

$(‘*’)
//*: A symbolic star.

Example:

$('*') selects all the elements available in the document. Following example would select all the elements available and would display them one by one.

    <html>
    <head>
    <title>The selector Example</title>
    <script type=”text/javascript” src=”/jquery/jquery-1.3.2.min.js”>
    </script>
    <script type=”text/javascript” language=”javascript”>
    $(document).ready(function(){
    var elements=$(“*”);
    for(i=0; i<elements.length; i++){
    alert(“Found element:” + elements[i].innerHTML);
    }
    });
    </script>
    </head>
    <body>
    <div class=”big” id=”divid1”>
    <p class=”para1” id=”pid1”>This is first paragraph</p>
    <p class=”para2” id=”pid2”>This is second paragraph</p>
    <p class=”para3” id=”pid3”>This is third paragraph</p>
    </div>
    <br />
    <div class=”big” id=”divid2”>
    <p>This is second division of the DOM.</p>
    <p>This is the second para inside the second division.</p> 
    </div>
    <br/>
    <div class=”medium” id=”divid3”>
    <p>This is para inside third division</p>
    </div>
    </body>
    </html>
    

jQuery-CSS Multiple Elements E, F, G selector

Description:

The Multiple Element selector selects the combined results of all the specified selectors E, F or G. You can specify any number of selectors to combine into a single result. Here orders of the DOM elements in the jQuery object are not necessarily identical. Like any other jQuery selector, this selector also returns an array filled with the found elements.

Syntax: Here is the simple syntax to use this selector

$(‘E, F, G, ….’)

Parameters: Here is the description of all the parameters used by this selector:

  • E: Any valid selector
  • F: Any valid selector
  • G: Any valid selector

Example:

  • $(‘div, p’): Selects all the elements matched by div or p.
  • $(‘P strong, .myclass ’): Selects all the elements matched by strong that are descendants of an element matched by p as well as all elements that have a class of myclass.
  • $(‘P strong, #myid’): Selects a single element matched by strong that is descendant of an element matched by p as well as element whose id is my id.

Following example would select elements with class ID big and element with ID divid3:

    <html>
    <head>
    <title>The selector Example</title>
    <script type=”text/javascript” src=”/jquery/jquery-1.3.2.min.js”>
    </script>
    <script type=”text/javascript” language=”javascript”>
    $(document).ready(function(){
    var elements=$(“.big, #divid3”);
    for(i=0; i<elements.length; i++){
    alert(“Found element:” + elements[i].innerHTML);
    }
    });
    </script>
    </head>
    <body>
    <div class=”big” id=”divid1”>
    <p class=”para1” id=”pid1”>This is first paragraph</p>
    <p class=”para2” id=”pid2”>This is second paragraph</p>
    <p class=”para3” id=”pid3”>This is third paragraph</p>
    </div>
    <br />
    <div class=”big” id=”divid2”>
    <p>This is second division of the DOM.</p>
    <p>This is the second para inside the second division.</p> 
    </div>
    <br/>
    <div class=”medium” id=”divid3”>
    <p>This is para inside third division</p>
    </div>
    </body>
    </html>
    

Comments/Suggestions are invited. Happy coding......!

Comments Post a Comment