Using active menu as input "radio"

0

I'm using a horizontal boostrap menu, its structure is basically like this:

<ul class="nav nav-pills">
  ...
  <li data-type="news" id="5" role="presentation"><a href="#">Link</a></li>
  <li data-type"sports" id="4" role="presentation"><a href="#">Link2</a></li>
  ...
</ul>

The idea is to click on each menu to call a jquery function to bring results with ajax and also activate the menu, if this structure were a list of inputs of the type "radio" would be more practical and quick to get all the attributes, is it possible, when selecting the menu, to mark the hidden "radio" input for this menu?

    
asked by anonymous 12.07.2017 / 19:36

1 answer

1

I believe that making this link between the radio buttons and the menu will cause more work, it will take events to keep both synchronized etc ...

I honestly do not see why creating this scheme with buttons radios, what you could do is create a generic click event for all menu items, and from there access the attributes and call the ajax

To access the data-type attribute for example, it would look like this:

$("ul.nav li").click(function(e){
    var dataType = $(e.currentTarget).attr('data-type');
    //...
});
    
12.07.2017 / 19:54