Search code examples
javascripthtmljaggery-js

Use a variable as an HTML element attribute


I am using Javascript loop to dispaly an HTML table rows. I could successfully do it.

There I use an array replyId

What I want is add the value of replyId[i] when running the loop to the "data-id" attribute in the following HTML tag in runtime.

<td id="forum_reply_content_cell_"+inputs.replyIds[i] data-id="">

How can I get this done?


Solution

  • I don't know this framework, but, from the demos I can see the you need to add <%= before the framework code (like .Net) and %> in the end. Something like this:

    <td id="forum_reply_content_cell_<%= inputs.replyIds[i] %>" data-id="">
    

    The demo source: https://github.com/wso2/product-jaggery/blob/master/apps/taskmaster/index.jag

    The framework reference: http://jaggeryjs.org/