PhotoJoe47
01-03-2006, 04:00 AM
I'm interesting in learning how to use the keyword "this". I want to know all the ins & outs. I have seen a few examples using the keyword but I feel my knowledge is not complete. I have google "javascript keyword this" but did not find anything that was helpful. I have also search a few on-line javascript references, but could not find a list of keywords.
I think you can, with an event handler use "this" to past a current object as an argument to a function. But I'm not quite sure how to pass it and then use it in the function.
Here is some code I was trying to play with.
<html>
<head>
<title>Some text for div 01</title>
<style type="text/css">
div
{
font-family: Comic Sans MS;
font-size: x-small;
font-weight: bold;
background: silver;
color: blue;
}
.bg1{background: lime}
.bg2{background: aqua}
</style>
<script type="text/javascript">
function changebg(something,bg)
{
somthing = bg;
}
</script>
</head>
<body>
<div id="div01">
<a href="#" onMouseOver="changebg(this,'bg2')" onMouseOut="changebg(this,'bg1')">Something</a>
</div>
</body>
</html>
I was trying to get the background color of the text "Something" that is between the opening and closing <a></a> tags.
I would like to learn enough about the keyword "this" to use it with any html element tag and event handler that the tag may have.
I think you can, with an event handler use "this" to past a current object as an argument to a function. But I'm not quite sure how to pass it and then use it in the function.
Here is some code I was trying to play with.
<html>
<head>
<title>Some text for div 01</title>
<style type="text/css">
div
{
font-family: Comic Sans MS;
font-size: x-small;
font-weight: bold;
background: silver;
color: blue;
}
.bg1{background: lime}
.bg2{background: aqua}
</style>
<script type="text/javascript">
function changebg(something,bg)
{
somthing = bg;
}
</script>
</head>
<body>
<div id="div01">
<a href="#" onMouseOver="changebg(this,'bg2')" onMouseOut="changebg(this,'bg1')">Something</a>
</div>
</body>
</html>
I was trying to get the background color of the text "Something" that is between the opening and closing <a></a> tags.
I would like to learn enough about the keyword "this" to use it with any html element tag and event handler that the tag may have.