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! :-)

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 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'." 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.

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?

  -- Scott

Reply via email to