Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8715231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:47:51+00:00 2026-06-13T05:47:51+00:00

I am updating a corporate site for a client, and I am not allowed

  • 0

I am updating a corporate site for a client, and I am not allowed to edit their html/css/php. When I need to make small changes, like add or remove from the main nav, I have to use a JS override file and jQuery. Like it or not, this is their system.

I am in need of adding a simple item to an unordered list. Targeting the UL is easy, as the nav wrapper has an ID. I don’t want to use nth:child since they want this new item between two specific other items, which may change. None of the LI tags have classes or IDs. Inside each LI is a link/anchor. I need to be able to pick the list item based on the text of the inner anchor.

<div id="nav">
<ul>
  <li><a href="">Something 1</a></li>
  <li><a href="">Something 2</a></li>
  // Need to insert here, but only because it must go after 
     Something 2, which itself may change positions in the future.
  <li><a href="">Something 3</a></li>
  <li><a href="">Something 4</a></li>
</ul>
</div>

Using jQuery, how can I most safely do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:47:53+00:00Added an answer on June 13, 2026 at 5:47 am

    This should do what you want..

    $('#nav li').filter(function(){
         return $(this).text() == 'Something 2';
    }).after('<li><a href="">Something new</a></li>');
    

    A more safe way for the comparison would be to trim and convert both string to lowercase.
    Additionally you should call your code after the DOMready event

    $(function(){
        var existingElement = 'Something 2'.toLowerCase();
        $('#nav li').filter(function(){
             var cleanText = $.trim($(this).text()).toLowerCase();
             return cleanText  == existingElement;
        }).after('<li><a href="">Something new</a></li>');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Updating an old ASP/Access site for a client - I need SQL to add
updating mysql connector from v3 to v5 caused Operation not allowed after ResultSet closed
Updating an inherited drupal site and I'm trying to add php code to the
After updating to php 5.3 one of our systems has developed an interesting bug.
Before updating jquery mobile on a site from version: v1.0b1 to the present: 1.2.0,
Edit : updating generalized question to reflect actual domain: sport of hockey. The actual
Updating: The php is considering the code beyond the EOM; closing tag. Here is
Edit: Updating post based on Martins comments below Hello, I'm just trying to get
Updating someone else's old PHP project and I'm unfamiliar with regular expressions. Question one
After updating Ubuntu 10.4, I'm not able to build any projects with errno.h used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.