perkov (perkov) wrote in javascript,
perkov
perkov
javascript

JavaScript. 2 issues

Hello.
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 "this.id" construction.
Perhaps this book is little outdated because it doesn't work under jQuery 1.4.2.
Calling "alert(this.id);" 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

    Error

    default userpic

    Your IP address will be recorded 

  • 3 comments