Reputation: 55
I am currently working on a school project and one of my functions is not running, onclick. I dont know why. I know its the function because i added a console.log() command.
HTML:
<div id="popup">
<div id="contain">
<div id="advert"><a href="#" onclick="close()" id="close">close</a></div>
</div>
<div id="block"></div>
</div>
JS:
function close(){
console.log("worked");
$("#popup").hide();
};
Upvotes: -1
Views: 52
Reputation: 277
You named your function close
, which is reserved for window.close()
and that is why it is not working. Just name it to something else and it will work :D cheers!
Upvotes: 0
Reputation: 3570
function closePopup(){
console.log("worked");
$("#popup").hide();
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="popup">
<div id="contain">
<div id="advert"><a href="#" onclick="closePopup()" id="close">close</a></div>
</div>
<div id="block"></div>
</div>
Your code didn't work because, close is an inbuilt function. Changing the name of the function do the trick.
Upvotes: 3