Reputation: 11
How do you set the dropdown box options using .addClass in javascript/jquery?
I need to set the options in the dropdown box to Link 1,Link 2, Link 3 etc but I cant figure out how to do it using .addClass
$hyperlinkElement = $('<a>Manage</a>').attr('href', '/Client/Visit/' + records[index].clientId).addClass('btn btn-primary dropdown-toggle');
Upvotes: 1
Views: 54
Reputation: 1246
With
$('dropdown-menu').addClass('item');
you only add a class - not an item.
For adding an item - you should use:
$('dropdown-menu').append("<a class='dropdown-item' href='#'>Link 1</a>");
You also have to set an event handler to trigger this:
<a class"manage">Manage</a>
<script>
$(".manage").on( "click", function() {
$('dropdown-menu').append("<a class='dropdown-item' href='#'>Link 1</a>");
});
</script>
Upvotes: 1