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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:44:18+00:00 2026-05-27T16:44:18+00:00

I am trying to do the following: A jumbled sentence is given and the

  • 0

I am trying to do the following:

A jumbled sentence is given and the user has to correct it

I have the jumbled sentence written inside a div and there is a text-box where in i get the user’s answer.

Now what i want is using jquery whatever he enters in the text-box gets strikedout (abc) from the question so that the user knows what words he has already selected.

This is my code:

$(document).ready(function() { 
    var orig=$('#original').html();
    $('#textbox').val(''); 
    $('#textbox').keyup(function(event) {
    var x=$('#textbox').val().split(" ");   
    $('#original').html(orig);
    for(var i=0;i<x.length;i++){
    $('#original').html($('#original').html().replace(x[i],'<del>'+x[i]+'</del>'));
    }
   }
  });

});

original is the id of the div containing the text and textbox the id of the textbox

This works fine for the cases where no word is repeated. But, if a word occurs more than once only the first occurrence of it is strikedout.

Can you give me a solution for the case where there are multiple occurences of a word?

For example, if the text is: posted of networking pictures can used on wrong sites on purposes leading social to lot for problems be

when I enter: “networking sites on” words networking, sites and first occurence of on should be striked off
then when i enter on again the second occurence of it should be striked out

  • 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-27T16:44:18+00:00Added an answer on May 27, 2026 at 4:44 pm

    Updated, based on the the comments below:

    $(document).ready(function() {
        var orig = $('#original').html();
        $('#textbox').val('');
        $('#textbox').keyup(function(event) {
            $("#original").html(orig);
    
            var x = this.value.split(" ");
    
            for (var i = 0; i < x.length; i++) {
                $("#original").contents().filter(function() {
                    return this.nodeType === 3 && this.nodeValue.indexOf(x[i]) >= 0;
                }).first().replaceWith(function() {
                    var re = new RegExp("\\b" + x[i] + "\\b");
                    return this.nodeValue.replace(re, "<del>" + x[i] + "</del>");
                });
            }
        });
    });
    

    Example: http://jsfiddle.net/E25Nd/3/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying the following xpath //tr[normalize-space(td/text())='User Name'] to get all the tr
I am trying the following code to AutoComplete contact details as the user types
I've following HTML, the div .info has display:none by default, I want to change
I'm trying the following with no luck. When the user click on a UiTextfield
I am trying following query to show all of my user at user page...
I have been trying following: <beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:context=http://www.springframework.org/schema/context xmlns:jee=http://www.springframework.org/schema/jee xmlns:mvc=http://www.springframework.org/schema/mvc xmlns:p=http://www.springframework.org/schema/p xmlns:util=http://www.springframework.org/schema/util ................
I'm trying to get the following layout of text containing both Hebrew and Latin
I have been trying the following but it returns unexpected results: Dim xd As
From the following HTML, I want to get the text inside the <label></label> with
I am trying following, 1. Get response using Ajax from the users selection which

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.