Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Try out my first PHP web app! Reply To: Try out my first PHP web app!

#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. ids 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 );
}