Redeem date-id from a menu

2

How do I pass the date-id of a menu link to a modal? For example I have a menu with the link1 - link2 - link3. When clicking for example in link2 open a modal displaying the values of link2. These values are retrieved from the database, so I need to know the data-id of the menu to pull the database information from that data-id.

    
asked by anonymous 19.12.2016 / 10:40

1 answer

0

To get the ID you can use a JavaScript function ... But you do not necessarily have to use a Data attribute, since you have the ID attribute. Then you can do whatever you want with it.

$(document).ready(function() {
  $('ul.menu > li').on('click', function() {
    var dataId = $(this).attr('id').replace('link-', '');

    console.log(dataId);
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><ulclass="menu">
  <li id="link-1"><a href="#">Link 1</a>
  </li>
  <li id="link-2"><a href="#">Link 2</a>
  </li>
  <li id="link-3"><a href="#">Link 3</a>
  </li>
</ul>
    
19.12.2016 / 11:20