Question: I have code like this 

```
<img onclick="getTitle();" title="myimg" >  
function getTitle()  
{  
alert(jQuery(this).attr("title");  
}  

```

and its not working. Can somebody explain how to do this right. And what is wrong with this code.

Answer: 
you left off a `)`

```
function getTitle()  
{  
    alert(jQuery(this).attr("title"));  
}  

```

Also since you are using jQuery it might be better to do this:

```
<img id="imgID" title="myimg" >  

jQuery('#imgID').click(function(){  
   alert(this.title);  
})

```
You forgot the `<script></script>` tags and you are also missing a `)` at the end of the `alert()` function. You also need to pass `this` in the `onclick` function so that you know which item is being called.

```
<script>
function getTitle(element)  {
    var objTitle = jQuery(element).attr("title"); 
    alert(objTitle); 
}
</script>
<img onclick="getTitle(this);" title="myimg" />

```

Also, having the `<script>` before will ensure this particular function works.

Or, to make it even more simpler, you could do this:

```
<script>
function getTitle(elementTitle)  { 
    alert(elementTitle); 
}
</script>
<img onclick="getTitle(this.title);" title="myimg" />

```