Goulash
Goulash

Reputation: 3838

Javascript - onClick return what was clicked on

so, I have a div with stuff like <h2>s and <img>s in them, and I want it so that if a user doubleclicks on one of them (for example they double click on anything inside the <h2></h2> tags it will turn it into a textbox with <h2>title</h2> inside it...

I just can't figure out how to send to the javascript function what was double clicked on?

Upvotes: 0

Views: 119

Answers (2)

Kaii
Kaii

Reputation: 20540

Here is a very bare example for single click:

<script type="text/javascript">
  function foo(elem) {
      elem.innerHTML = '<input type="text" value="' + elem.innerHTML + '">';
  }
</script>
<h1 onClick="foo(this)">Hello</h1>
<h1 onClick="foo(this)">My</h1>
<h1 onClick="foo(this)">Friend</h1>

test live: http://jsfiddle.net/MsTzY/

Upvotes: 1

amd
amd

Reputation: 21462

try if you are famous with jQuery:

$('#yourDiv *').dblclick(function(event)){
 alert(event.target.html());
}

Upvotes: 2

Related Questions