PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 19, 2022

[FIXED] How to show dropdown links in a particular order?

 November 19, 2022     bootstrap-4, drop-down-menu, html, jquery     No comments   

Issue

I want to show the drop-down links in a particular order. Right now the order is -

  • Link 1
  • Link 3
  • Link 2

HTML Code -

<ul class="navbar-nav">
  <li class="nav-item dropdown">
    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"></a>
      <ul class="dropdown-menu">
         <li><a class="dropdown-item" href="#">Link 1</a></li>
         <li><a class="dropdown-item" href="#">Link 3</a></li>
       </ul>
  </li>
</ul>

Javascript Code -

if (role == "admin") {
  $(".dropdown-menu").append('<li>'+
  '<a class="dropdown-item" href="#">Link 2</a>'+
   '</li>');
}

Can anyone tell me how can I show the links in the following order?

  • Link 1
  • Link 2
  • Link 3

Solution

if (role == "admin") {
  $(".dropdown-menu :first").after('<li>'+
  '<a class="dropdown-item" href="#">Link 2</a>'+
   '</li>');
}


Answered By - Vivekanand Vishvkarma
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing