I have the following HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Case</title>
<script src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
//Change a single directory
function changeDirectory(attrib, odir, ndir) {
var re = "/$.\/" + odir + "\//";
var srcv = $(this).attr(attrib);
var nv = srcv.replace(re, ndir);
}
</script>
</head>
<body>
<button id="spanishButton" lang="spa" type="button"
title="Tomá usted a una página en Español" value="Español">
<img src="images/large/spain-map-with-flag.png" width=110
height=80/></button>
<script type="text/javascript">
$("#spanishButton > img").each(changeDirectory("src", "large", "medium"));
</script>
</body>
</html>
The intent is to change the path to the image associated with a button. When I load the page, I get "undefined" returned from line 2 of the function "changeDirectory" which suggests that $(this) is not the jquery object for the image used with the button.
Can anyone see what I am doing wrong or suggest an alternative way of reaching my objective.