I'm going to build a page with just the basic code for responding to the
click then add the libraries and see if that makes things fail. I'll post a
message about. My comments are below and I appreciate your taking the time
to explain this to me.

 

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Scott Sauyet
Sent: Friday, July 20, 2007 1:07 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Click to call a fuction?

 

 

Mitchell Waite wrote:

> How generous of you to go into this detail and give me so many options.

> Sadly I tried all of these techniques and none of them worked.

 

Could you post a sample page somewhere where these fail?  This is pretty 

basic JQuery.  I'm wondering if there is some interference with another 

library.  Have you looked at them in Firebug?

 

One more possibility:  Is your code inside a $(document).ready() block? 

  If not, and if it's running in the head of the document, then JQuery 

doesn't have any DOM elements to work with.

 

     <script type="text/javascript" src="/path/to/jquery.js"></script>

     <script type="text/javascript">

         $(document).ready(function() {

             alert("DOM loaded.  JQuery will now work");

             // put your code here

         }

     </script>

 

> I need to read more about selectors.

> 

> It may also be my project has too many bells and whistles that it's not a

> true test of your ideas.

 

Only if one of those bells is not working well with JQuery.  It happens, 

especially if other code is using the "$()" function.

 

 

> -----

> Essentially, you need some way with CSS (or possibly XPath) selectors to 

> distinguish the elements that need your new behavior.  Create a selector 

> for those elements and create a JQuery object from them using the "$()" 

> function.  Then it's easy to send a behavior to the click method of this 

> JQuery object.

> ------

> 

> I have read this 10 times and I am still not sure what you are saying. 

 

Concise, elegant, and completely unreadable, huh?  My wife says that all 

the time!  :-)

 

And I bet she is a great at getting to explain it to mere mortals.

 

One more try:  You have a number of elements to which you want to attach
certain behavior.  The core of JQuery has to do with how you select 

those elements.  JQuery will accept a description of the set of elements you
want (a "selector") and walk through the document object model (DOM)
creating a single object that wraps up all matching elements.  

 

This concept of "walking" is something that I am not familiar with. In fact
I have to say that I am not well versed in the DOM and I think that is
lowering my ability to get the big picture, so that is part of my work
ahead. I certainly get the essence of your point, which is the ability to
take a collection of css and HTML and manipulate it as a single element with
JQuery and all its tools. Is there a place I can learn all about the DOM
that is not super technical?

 

This lets you work with these elements in many ways as though they were a
single element.

 

When you run this:

 

     $("#myDiv img.myClass").click(someFunction)

 

what you are doing is creating a CSS-based selector, "#myDiv img.myClass",
which can be thought of as "all the images whose classes include 'myClass'
and are contained in the element with the id 'myDiv'." 

 

So you mean: if you have something like an HTML table with 6 "<img
src=href.." statements in it, and you give each of these a "class=myClase"
then every one of those images will be considered by jQuery to be the ID of
their main container DIV, which is #myDiv here. So you are able to perform
some cool manipulation of all those imgs. Is that close?

 

You are wrapping those in a single JQuery object by calling the "$()"
function with that selector.  Then, you are calling the method "click" on
that object, passing in the function as a parameter.  Behind the scenes,
JQuery is binding that function to the click event of each matching element.

 

I think I get this.

 

The variety and the brevity of selectors you can apply is one of the
hallmarks of JQuery.  But for your purposes, simple selectors, such as 

"img.myClass" would probably be enough.

 

Does that make any more sense?  Or am I just confusing the issue?

 

It helps a TON Scott.

 

I read the Selectors docs. Pretty useless to me. The entire subject is
confused by the inclusion of xpath and no real world example. I could not
make any thing of its contents.

 

   -- Scott

 

Reply via email to