perkov (perkov) wrote in javascript,

JavaScript. 2 issues

I'm a newbie in JavaScript (and jQuery, too).
I've got some little troubles with it.

First. I'd love to know how to obtain an ID of clicked element inside click event handler.
According to the book "Learning jQuery" by Jonathan Chaffer and Karl Swedberg, I gotta use "" construction.
Perhaps this book is little outdated because it doesn't work under jQuery 1.4.2.
Calling "alert(;" in the event handler is resulting in "undefined" message.

Second. I'm trying to figure out how to attach a click event handler to the element created dynamically by script.
The following line of code is resulting in new unclickable picture on my page:
myDiv.innerHTML = myDiv.innerHTML + '<img alt="" class="Pics" src="img2.jpg" onclick="return ClickIMG()" />';
This problem is not being solved by using the code like this: $('.Pics').Click('ClickIMG').

I think these issues are quite common and can be easily solved.
So you probably can help me.
Thank you.
  • Post a new comment


    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.