Hi everyone, i need your help)
i have some elements with same id, say:

<div id="myid">Data1</div>
<div id="myid">Data2</div>

I want to get innerHtml when one of them is clicked, how can i determine which one exactly was clicked?


//how to get the .html and other properties of clicked element?


Edited by Acute: n/a

6 Years
Discussion Span
Last Post by Acute

Ids must be unique, so you will need to change the id of at least one of them or you will likely experience cross-browser incompatibilities. However, it is OK to have multiple elements with the same class name. So, if you change those id='myid' to class='myid' then use $('.myid:eq(0)').html() to get the innerHTML of the first div. For the second div, change the zero to a ONE.


Ok, thank you. However, i still have a question: how to get the inner html or other property of the element that was just clicked?
For example i have a menu, or some table and the elements of this table have same class but dynamically given different ids. Now i want to get the id value when mouse is clicked on any element of the table. How can i do it? is there anything like this[/COLOR.html()]?


To get the innerhtml of the clicked item you only need:


The keyword "this" refers to the element that triggered the event.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.