Maneuver DOM Elements in ASP.Net with JQuery

JQuery, a popular open source JavaScript library, is CSS3 compliant. With JQuery, you can easily maneuver the DOM elements in your web page. Basically, it allows you to add/delete DOM elements to your HTML based content.
If you want to manipulate the DOM elements using JQuery and Visual Studio, you basically need to install the following tools to your system
- Visual Studio 2008 and 2008 SP1
- JQuery Library
- The VS 2008 JQuery Plugin
Let's see how to manipulate the elements using jQuery plugin
Manipulating the DOM Elements
You simply need a few CSS classes to begin the manipulation process. Use the following code to add a CSS class to the DOM element
$('#DOMElement').addClass('CSSClassName');
You can use the following code to remove a CSS class associated with a DOM element
$('#DOMElement').removeClass('CSSClassName');
With the following code, you can easily check if a CSS class is bound to a DOM element
$(#DOMElement).hasClass(myCSSClass)
To know if an element exists, use the length property through the following code
if ($('Image1').length)
{
alert("Found");
}
else
{
alert("Image object not found");
}
Making it simpler, is the following code
if ($("#Image1").length)
alert("Found");
else
alert("Not found");
Here is a code if you want to set values to the various CSS attributes. An example of color as the attribute is being considered here
$('#ErrorDiv').css("color","red");
Here is the code to retrieve an element's property
$('#MyDiv').css('font-weight');
In JQuery the.append() and .appendTo() work in pretty much the same way; they differ only in their syntax
<div class="test">
<div class="first">Hello</div>
<div class="last">World</div>
</div>
If you use AppendTo () the code transforms as follows
$('<p>This is a sample text</p>').appendTo('.first');
Let's have a look at the final HTML code
<div class="test">
<div class="first">
Hello
<p>This is a sample text</p>
</div>
<div class="last">
World
<p>This is a sample text</p>
</div>
</div>
Deepa is a passionate blogger associated with Semaphore Software. A leading Offshore development company. She loves sharing information regarding asp.net development tips & tricks. If you are looking for Hire asp.net developers then just get in touch with her.
Comments