Search code examples
javascriptjquerycssspring-mvctiles2

Highlight a row on table which is filled dynamically by assync resquest data


I have to update a table with rows which have data received by assync requests (JSON format). I'm doing this task very well (to create rows with the received data dynamically). Now I'm trying to set some events in those rows, such as highlight them when user pass mouse over, and show specific information of a row in a other div when user click on it.

I've tried many ways to do it, but nothing happens. The events simply don't work at all. I'm using Spring Framework mvc and the view layer is based on Tiles templates (header.jspx, menu.jspx, footer.jspx, etc).

I have to put the jquery code on another place ? Someone could help to solve this problem please?


Solution

  • It is not possible to give an exact answer without seeing the code, but I'm guessing you're binding the events to the elements before they are created. This is a common pitfall among JavaScript programmers.

    You have to bind your event listeners (eg: .addEventListener() or jQuery's .click()) after the elements are created. In your JavaScript code, add them after you create the HTML elements from the async data.