Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<UL> Menu in single file, then call it in all HTML web pages

On my html web page I have designed menu as a UL (Unordered List)

Now I have multiple pages. In case I add one menu item, then I have to edit all web pages.

I simply want that I could create my menu UL (unordered list) in a separate file i.e. js file (or any other file) and call it in my all html web pages. So that when ever I have to add a new item in my menu, I would simply add menu item in one file; rather then editing all html web pages.

Please give me any solution or guide me please.

Thanks in advance.

like image 724
Anwer Hussain Avatar asked Dec 07 '25 03:12

Anwer Hussain


1 Answers

You will need to replicate this code in all your html files.

<body>
    <ul class='my-list'></ul>
</body>

Js:

var list = `<li>Dummy 1</li><li>Dummy 2</li>`;
$(".my-list").append(list);

This could be one of the many ways, but i think this is the easiest one to do your job. You will only need to change the JS code whenever you want to add a new list item.

like image 117
Akash Tomar Avatar answered Dec 08 '25 15:12

Akash Tomar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!