I've been trying to get this to toggle two .pngs on button click. When I run the code, console throws and error: Uncaught TypeError: object is not a function. Here is my code:
<body>
<h1>My Website</h1>
<div>
<button data-file="bs">BMW </button>
<button data-file ="ms">Mercedes</button>
</div>
<div id="bmw">
<img src="bmw.png">
</div>
<div id="mercedes">
<img src="merc.png">
</div>
<script src="http://ift.tt/13qgtmt"></script>
<script>
(function(){
var link = $('link');
$('button').click(function() {
var $this =$(this)
car = $(this).data('file');
console.log(car);
link.attr('href', car + '.png');
});
})();
Which object is this referring to? And how do I alter the code?
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire