I want to open a warning window when I click on a specific link. How to do it?
You can also use the following codes:
<a href="#" id="link">Link</a>
JavaScript:
$(document).on("click","#link",function(){ alert("I am a pop up ! "); });
OR
<a href="#" onclick="alert('I am a popup!');">Link</a>
Without using a JS file (only as an alternative to already posted answers):
<a href="http://example.com" onclick="alert('Hello world!')">Link Text</a>
<a href="#" onclick="myFunction(); return false;">
return false; will stop loading the webpage after clicking.
return false;
JavaScript Code:
function myFunction() { alert("I am a pop up ! "); }
The following code may help: -
<a id="anchor">i am the anchor</a> <div id="popup">this is a popup</div> <script> $(function(){ $('#popup').hide(); $('#anchor').click(function(){ $('#popup').show(); }) }); </script>