Goofy wrote:
What happens if you already have some 3rd party class on the image
like this:

<img src="images/Advanced Search Glossy_WIDE.jpg" class="glossy
iradius50" alt="" />

If I add an ID the click never gets fired

<img src="images/Advanced Search Glossy_WIDE.jpg" id="PanelOpenGlossy"
class="glossy iradius50" alt="" />

It should.  This

    $('#PanelOpenGlossy').click(function(){
        alert('testing');
    }

should work.

My other question is this: the ID has to be unique for this approach
to work, right? You can't call the same function but have to make a
new one. That seems inefficient as I would be repeating the same
function for every click, only difference would be there IDs.

If you can add an additional class, e.g. class="glossy iradius50 xyz", to all the relevant images, then you can simply change the selector above:

    $('.xyz').click(function(){
        alert('testing');
    }

Notice the change from "#" to "."; this is the CSS way of switching from ids to classes.

If you can't add this class, you'll need to find some other way of distinguishing them from images that shouldn't have this functionality. For instance if this is all the images inside any div with class "clickable", then you might use:

    $("div.clickable img").click(function() {
        alert('testing');
    }

Or if you need only those images inside the div with id "main" that don't have the class "ignoreMe", you might try

    $("#main img").not(".ignoreMe").click(function() {
        alert('testing');
    }

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.

Good luck,

  -- Scott

Reply via email to