<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript">
function foo() {
$(this).parent('li').append('hello world');
}
</script>
<ul>
<li><img src="http://www.gravatar.com/avatar/a3981906ca415e0ec3e051076b71b0cd?s=32&d=identicon&r=PG" onClick="foo()" /></li>
<li><img src="http://www.gravatar.com/avatar/8ec1383b240b5ba15ffb9743fceb3c0e?s=32&d=identicon&r=PG" onClick="foo()" /></li>
</ul>
I’m trying to append the string “hello world” to the <li> that contains the image that was just clicked.
no need to attach onclick. With jQuery just do
Check working example at http://jsfiddle.net/tFr5y/