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!


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 ='data-username');
    console.log( username );