javascript - Cannot add two hyperlinks at the same time using JQuery -


i have application using asp.net mvc. trying put submenu @ side navigation when click on dropdown. since have multiple submenus single dropdown, put of side navigation. use code:

<li id="dd_vehicle" class="dropdown"> <a id="x_btn" href="#" class="dropdown-toggle" data-toggle="dropdown"  >vehicle <b class="caret"></b></a> <ul class="dropdown-menu">      <li id="item_registration">         @if (utils.isadmin())         {             @html.actionlink("registration", "registration", "home")         }     </li>     @*}*@       <li id="item_modify">         @html.actionlink("modify", "modify", "home")     </li>      <li id="item_history">         @html.actionlink("history", "history", "home")     </li>      <li id="item_vehicle_transaction">         @html.actionlink("transaction", "transaction", "home")     </li> </ul> </li>  $(document).ready(function () { $('#x_btn').on('click', function (evt) {     //evt.preventdefault();      $('#links_area').html('<a href="@url.action("registration", "home")" class="btn btn-primary">registration</a>');     $('#links_area').html('<a href="@url.action("transactionreport", "home")" class="btn btn-primary">modify</a>');      }); }); 

the problem is, cannot put 2 of links @ same time. "#links_area" holds 1 of links , last link added. please help. thank you.

you can use .append() instead of .html()

$(document).ready(function () {     $('#x_btn').on('click', function (evt) {         //evt.preventdefault();         $('#links_area').append('<a href="@url.action("registration", "home")" class="btn btn-primary">registration</a>');         $('#links_area').append('<a href="@url.action("transactionreport", "home")" class="btn btn-primary">modify</a>');      }); }); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -