-2

Say I have the following code

<div id='div1'>
 <div onclick="f1(parent div tag)">
   hello
 </div>
</div>

I think my code is clear. Here I want to access the <div> with id 'div1' (or say the id of it if available) to send it as a parameter to the JavaScript function f1(). How can I do It?

I am getting no reference for exactly this problem from anywhere else. Please help me out.

Rajesh Paul
  • 6,793
  • 6
  • 40
  • 57

1 Answers1

1

Use parentNode

    alert(obj.parentNode.getAttribute('id'));

Refer LIVE DEMO

Siva Charan
  • 17,940
  • 9
  • 60
  • 95