On 16 Giu, 06:07, Jordban <[EMAIL PROTECTED]> wrote:
> I'd like to create an image that when clicked changes the html of a
> div. I'd like to have many different images that change the content of
> many different divs with different html.

hi :)
you don't need to create functions and pass parameters, neither you
need to use old 'onclick' attribute.
you simply attach a jQuery handle to images that have a certain class
(for example).
let's say those images are '.textChanger'.

$('.textChanger').click(function(){
    // code here
});

now this is listening for a click on those images. each and every one
of them.
every time the event is fired, the code is executed.

what code?
I would do something like this (but it's just my way, there are surely
many other, and better).
I'd use the class name to store the id of the div that is going to be
changed.
if the class was like 'textChanger_div1', you could use a split()
method to get the id of the div.
like this:

$('img[class^=textChanger]').click(function(){
    var $this = $(this);
    var the_id = $this.attr('class').split('_')[1];
    $('#' + the_id).html('<strong>cool this is bold</strong>');
});

$('img[class^=textChanger]') means: look for the images that have a
class whose name starts with the string 'textChanger'.
hope this helps

andrea

Reply via email to