jquery css change

So i have some spans that when i rollover one of them i want to change the font of that particular one do a different color, so i am thinking that i can just change the css close, but i dont know how to in Jquery assign a new css class to the current affected interacting item.  In other words there are multiple spans with the .tab_item class, i just wont to change the one that i am over, and have it reset when im off it.
<script>
$(document).ready(function()
{
  $(".tab_item").mouseover(function()
  {


  });
  $(".tab_item").mouseout(function()
  {


  });

});
</script>
<style>
.tabs .tab_item {
	display: block;
	float: left;
	padding-top:34px;
	width: 160px;
	
	text-align: center;
	z-index: 200;
	position: relative;
	cursor: pointer;
	font-size:16px;
	font-family:Arial;
	color:#ffffff;
}
</style>

<span class='tab_item'>
Our Company!
</span>
<span class='tab_item'>
Information
</span>
<span class='tab_item'>
Contact Us
</span>

Open in new window

LVL 4
Brant SnowAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
Hello thawts,

i.e : $(this).css("color", "#888888");

Check this :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.tabs .tab_item {
        display: block;
        float: left;
        padding-top:34px;
        width: 160px;
        
        text-align: center;
        z-index: 200;
        position: relative;
        cursor: pointer;
        font-size:16px;
        font-family:Arial;
        color:#ffffff;
}
</style>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$(".tab_item").mouseover(function() {
			$(this).css("color", "#888888");
		});
		$(".tab_item").mouseout(function() {
			$(this).css("color", "#000000");
		});
	});
</script>
</head>
<body>
<span class='tab_item'>
Our Company!
</span>
<span class='tab_item'>
Information
</span>
<span class='tab_item'>
Contact Us
</span></script>
</body>
</html>

Open in new window

0
 
Steve KrileConnect With a Mentor Commented:
You could go with the .hover() and .toggleClass() methods in jquery.

.hover() is nice because it compacts the mouseover and mouseout functions into one.

.toggleClass is nice because you can conditionally add a function inside the toggle class to inspect the current thing you want to toggle and decide what class to toggle.

You can read more about toggleClass here:

http://api.jquery.com/toggleClass/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>Untitled Document</title>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
		<style>
			div.hover {font-size: 12px;cursor:pointer;}
			div.hover_on {font-size: 18px;background:yellow;}
		</style>
		<script type="text/javascript">

		$(function(){
			$("div.hover").hover(
				//mouseover function
				function(){
					$(this).toggleClass("hover_on");
				},
				//mouseout function
				function(){
					$(this).toggleClass("hover_on");
				}

			);
		})
		</script>
	</head>
	<body>
		<div class="hover">
			This is a smaller text to start...but bigger when hovering.
    	</div>
	</body>
</html>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.