Hello @Mohammad Qasim ,
You can use the below Jquery script to achieve your design:
Please the following steps:
1 Copy the Jquery script and store the .js file in the Site Assets Library
2 Go to SharePoint List, click on Edit page
3 Add a web part named "Content Editor" under the Media and Content section

4 Edit Web Part >> go to the Content Editor panel, copy the address link of the .js file to the Content Link textbox.

5 Stop Editing to save page

Thanks,
Echo Du
========================
Updated Answer =======================
Hi @Mohammad Qasim ,
This is because the Custom Script function is not enabled in your environment.
There are two ways to enable the Custom Script function:
- Step1: Using SharePoint admin center (It takes 24 hours to take effect)
1.1 Sign in Classic SharePoint admin center as a global or SharePoint admin.
1.2 Click on settings tab on the left navigation bar.

1.3 Scroll page to Custom Script section, as shown below:

- Step2: Using PowerShell command (Effective immediately)
1) Run SharePoint Online Management Shell as a global or SharePoint admin.
2) Execute the following command:
Connect-SPOService -Url https://xxxx-admin.sharepoint.com
Set-SPOSite -Identity https://xxxx.sharepoint.com/sites/projects -DenyAddAndCustomizePages 0
Thanks,
Echo Du
========================================
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Below is snap for reference
