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 6115317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:04:37+00:00 2026-05-23T15:04:37+00:00

When I user click on the button remove word and as enter 2 in

  • 0

When I user click on the button remove word and as enter 2 in the input box it should remove it from the element id=”list”

<input type="text" id="word"><input type="button" value="remove word">

<span id="list">1,2,3</span>

I did the following on the click event:

var text = $('.word').val();
    $('#list').html($('#list').html().replace(/text/ig, ""));

I understand it looks for the string text and not the var. So how can I change the syntax to make it search for the var.

  • 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-05-23T15:04:37+00:00Added an answer on May 23, 2026 at 3:04 pm

    Literal regexps (/.../) are literal in such a way that they cannot contain variables. You’d need to construct a regexp this way:

    var text = $('.word').val();
    $('#list').html($('#list').html().replace(new RegExp(text, "ig"), ""));
    

    Edit: If you need to have following commas removed, you’d be best off by parsing it as an Array and removing the appropriate element:

    var text = $('.word').val();
    var array = $('#list').html().split(","); // split into an Array
                                              // items are delimited by a comma
    while(array.indexOf(text) > -1) {         // as long as text is in the array...
        array.splice(array.indexOf(text), 1); // remove one element from the array
                                              // at the position the text is
    }
    $('#list').html(array.join(","));         // concatenate the elements with a
                                              // comma again
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application, the user click a delete button to delete items from a
i have created Array of Linkbutton and when user click on link button it
I have 4 tabs in my iphone application. When user will click a button
User click on a link button and it will direct them to a url
Suppose, I want to have a link or a button that when user click
I don't want to allow user to double click on my button. On the
Example: The user login to the webpage => Click on a button This action
I need a function that a user can just click a flash app button
How can I force validation when user clicks button? One would think this should
My goal: the user clicks a button. From the button pops up a two-level

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.