Hi there,

a couple of things. First, you can create your selectors the same way you do with css rules (but you can actually use all the selectors from css 1-3 with jQuery). So, inside the $(), just put in "#menu a".

Then, when you're dealing with links, you'll need to stop the default behavior (which is to try to send you to the URL referred to in the href). You can do that a couple ways, but the simplest is by add a line with return false; in it.

Here is a modified version of your script with the changes I mentioned above:

$(document).ready(function(){
         $("#menu a").click(function(){
           alert("Thanks for visiting!");
           return false;
         });
 });



--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Oct 29, 2007, at 3:04 PM, Vik_R wrote:



I'd like to attach an onclick function to the links that are in a specific
div. The id of the div is "menu". I tried variations on this:

$(document).ready(function(){
         $("#menu").("a").click(function(){
           alert("Thanks for visiting!");
         });
 });

...but I was just guessing, and I didn't find the correct way yet.

What is the correct way to do this? Thanks very much in advance to all for
any info.
--
View this message in context: http://www.nabble.com/Newbie-Question% 3A-Specifying-the-links-that-are-in-a-particular-Div-- tf4713851s27240.html#a13474559 Sent from the jQuery General Discussion mailing list archive at Nabble.com.


Reply via email to