Select Items With Class and Id in jQuery

How to get an element from DOM based on ID and Class.

Recently I started working with jQuery and went through the jQuery core methods.
I've used a very basic approach to describe these functions.
This is a very basic structure which exists by default whenever you create any project into VS 2010.

The scripts folder in the above image contains 3 Java script files with extension the ".js". Jquery-1.4.1.js and other files are present in the VS 2010 default application, there is no need to add these files to the solution. You can start working on jQuery as you create a default solution with VS 2010.
Let's get to the main point for playing around with jQuery.
The page script is given below:

An unordered list having list elements along with the style attribute, which we'll be using later in the current document. I've added the reference for the jQuery files. The applcaition is divided into two parts and exists as part 1 and part 2.
Part 1:
The folowing is the output of the application as it is run the first time.

I've used this line segment to get an output.

The code above selects an element having id="first" and adds the CSS class to the selected element from the DOM.

Part 2:

This is an output of the application after using the "$('li.selected').remove();" code. If you notice, the third element has been removed from the DOM.

The above sample is used to select an element based on ID and a class from the DOM. The sample application has been attached as a reference.
Long way to go with jQuery.

Up Next
    Ebook Download
    View all
    View all