Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery event handling for links
    primarykey
    data
    text
    <p>I'm getting started with jquery and following the tutorial on the official website found here. <a href="http://docs.jquery.com/How_jQuery_Works#jQuery:_The_Basics" rel="nofollow">http://docs.jquery.com/How_jQuery_Works#jQuery:_The_Basics</a></p> <p>I'm in the section labeled Launching Code on Document Ready. If you notice, they provide two examples. One where an alert box pops up before taking you to jquery site, and another where an alert box prevents you from going to the site.</p> <p>Suppose I want to have two links. One where an alert box appears and upon clicking "OK" it then proceeds on to jquery's site, and another that an alert box appears but prevents you from going to jquery's site. I'd just like to be able to figure out different responses for different links. Do I need to give it some sort of id?</p> <p>Here's the code.</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Demo&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script src="jquery.js"&gt;&lt;/script&gt;&lt;br/&gt; &lt;a href="http://jquery.com/" id="1"&gt;jQuery&lt;/a&gt;&lt;br/&gt; &lt;!--first link: will display message and then proceed to site --&gt; &lt;script&gt; $(document).ready(function(){ $("a#1").click(function(event){ alert("Thanks for visiting!"); }); }); &lt;/script&gt; &lt;a href="http://jquery.com/" id="2"&gt;jQuery&lt;/a&gt; &lt;!-- second link: message appears and does not continue to site --&gt; &lt;script&gt; $(document).ready(function(){ $("a#2").click(function(event){ alert("As you can see, the link no longer took you to jquery.com"); event.preventDefault(); }); }); &lt;/script&gt; </code></pre> <p> </p> <p>edit - added id's to anchors. Thank you guys, it works. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload