jQuery and ASP.NET

January 8, 2009

Add CSS to Ordered and Unordered List using jQuery




I was working on a solution where I had to add CSS to a bunch of <li> inside <ul>. I used jQuery to do in the following manner:

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title></title>
<
style type="text/css">
.clsLI
{
color:Gray;
cursor:pointer;
}
</style>
<
script src="http://code.jquery.com/jquery-latest.js"
type="text/javascript"></script>


<
script type="text/javascript">
$(document).ready(function() {
$("ul#unord li").hover(
function() {
$(this).addClass("clsLI");
},
function() {
$(this).removeClass("clsLI");
}
)
});
</script>
</
head>

<
body>
<
form id="form1">
<
div>
<
ul id="unord">
<
li>
jQuery
</li>
<
li>
JavaScript
</li>
<
li>
jQuery and JavaScript
</li>
</
ul>
</
div>
</
form>
</
body>
</
html>

In the code above, the CSS gets applied when the user hovers the mouse on a <li>. In this example, we hover the mouse over 'JavaScript'. The output is as shown below:




'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Add CSS to Ordered and Unordered List using jQuery"
 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions