Home › Forums › Back End › Try out my first PHP web app! › Reply To: Try out my first PHP web app!
September 21, 2014 at 5:21 pm
#183800
__
Participant
I used the data-attribute earlier today and it gave me the same problem.
Not quite: you’re not even getting to the part where you try to use the data attribute, because you’re still trying to select an element by a non-unique id
. You can’t do this. It will never work. id
s must be unique on a page.
If you use modern event listeners, then you’ll get the event object when it fires, and you can find the element you’re looking for very easily:
function commentbox_onClick( event ){
var username = event.target.parentNode.getAttribute('data-username');
console.log( username );
}