1

I have a json structure is like this..

{
"event": [
    {
        "ids": [
            "100",
            "101"
        ],
        "eventlist": [
            {
                "title": "Title1",
                "day": "Fri",
                "date": "2",
                "endDate": "6",
                "month": "1"
            },
            {
                "title": "Title2",
                "day": "Mon",
                "date": "5",
                "endDate": "5",
                "month": "1"
            }
        ]
    }
]
}

HTML Handlebar template..

{{#event}}
  {{#each eventlist}} 
   <li>
      <div>{{title}}</div>
      <div>{{day}}</div>
      <div>{{month}}</div>
   </li>
   {{/each}}
{{/event}}

How can i store the values title,day,month as a jquery.data() value into the li , so that i can access the data of li using li.data()

1 Answer 1

3

Just add them as data attributes:

<li data-title="{{title}}" data-day="{{day}}" data-month="{{month}}">

jQuery will be able to access them through .data():

var title = $('li').data('title');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.