elepil
asked on
Weird jQuery/JavaScript problem.
I set up two mouseup() event handlers for two separate objects, each of which when clicked, is supposed to go to two different websites. The first object, when clicked, should go to amazon.com, and the second should go to ebay.com. But somehow, both keep going to ebay. Can someone please tell me why this is happening?
Here is the code:
Thanks.
Here is the code:
<html>
<head>
<style>
html {
min-width: 300px;
height: 100%;
}
#testDiv {
margin: 0 auto;
display: inline-block;
background: red;
border: 3px solid white;
width: 300px;
height: 300px;
}
.testItem {
width: 50px;
height: 50px;
background: green;
border: 1px solid white;
cursor: pointer;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function() {
var obj1 = $("#testDiv").append("<div class='testItem'>Test Item 1</div>");
obj1.mouseup(function() {
location.href = "http://www.amazon.com";
});
var obj2 = $("#testDiv").append("<div class='testItem'>Test Item 2</div>");
obj2.mouseup(function() {
location.href = "http://www.ebay.com";
});
});
</script>
</head>
<body>
<div id="testDiv">
</div>
</body>
</html>
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome. Although I spotted the problem, Tom knew how to fix it.
Thanks for the points.
ASKER
Thank you for your help. More points given to Tom Beck because he provided code correction, even though Dave spotted the problem first.