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

The Archive Base Latest Questions

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

I have the following div : <div id=query style=width:500px; height:200px;border:1px solid black spellcheck=false contenteditable=true></div>​

  • 0

I have the following div:

<div id="query" style="width:500px; height:200px;border:1px solid black"
 spellcheck="false" contenteditable="true"></div>​

where Clients can write their SQL queries. What I was trying to do is wrap words the client enters right after hitting Space with a span and give this span a certain class according to the word typed:

example

If the client types select i need to wrap this select word like this in the div:

<span class='select'> SELECT </span> <span> emp_name </span>

CSS

.select{color:blue ;text-transform:uppercase;}

It is something very similar to what jsFiddle does. How can i achieve this?

Here is what i have tried so far : jsFiddle

$(function(){
    $('div').focus() ;
    $('div').keyup(function(e){
        //console.log(e.keyCode) ;
        if(e.keyCode == 32){
            var txt = $('div').text() ;
            var x = 'SELECT' ;
            $('div:contains("'+x+'")').wrap("<span style='color:blue ;
      text-transform:uppercase;'>") ;
            if(txt == 'SELECT'){
                console.log('found') ; // why This Doesn't do any thing  ?
            }

        }
    });

});
  • 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-13T22:51:33+00:00Added an answer on June 13, 2026 at 10:51 pm

    I did a proof of concept with some modifications from what you originally had. See below,

    DEMO: http://jsfiddle.net/cgy69/

    $(function() {
        $('div').focus();
        var x = ['SELECT', 'WHERE', 'FROM'];
        $('div').keyup(function(e) {
            //console.log(e.keyCode) ;
            if (e.keyCode == 32) {
    
                //using .text() remove prev span inserts
                var text = $.trim($(this).text()).split(' ');            
                $.each(text, function(i, v) {
                    $.each(x, function(j, xv) {
                        if (v.toUpperCase() === xv) {
                            text[i] = '<span style="color: blue; text-transform: uppercase;">' + v + '</span>';    
                        }                                        
                    });
                });
    
                $(this).html(text.join(' ') + '&nbsp;');
    
                setEndOfContenteditable(this);
            }
        });
    
        function setEndOfContenteditable(contentEditableElement) {
            var range, selection;
            if (document.createRange) //Firefox, Chrome, Opera, Safari, IE 9+
            {
                range = document.createRange(); //Create a range (a range is a like the selection but invisible)
                range.selectNodeContents(contentEditableElement); //Select the entire contents of the element with the range
                range.collapse(false); //collapse the range to the end point. false means collapse to end rather than the start
                selection = window.getSelection(); //get the selection object (allows you to change selection)
                selection.removeAllRanges(); //remove any selections already made
                selection.addRange(range); //make the range you have just created the visible selection
            }
            else if (document.selection) //IE 8 and lower
            {
                range = document.body.createTextRange(); //Create a range (a range is a like the selection but invisible)
                range.moveToElementText(contentEditableElement); //Select the entire contents of the element with the range
                range.collapse(false); //collapse the range to the end point. false means collapse to end rather than the start
                range.select(); //Select the range (make it the visible selection
            }
        }
    });
    

    You going to extend this further to handle

    1. Backspace
    2. HTML contents from previous inserts
    3. Cursor position Partially done, editing in the middle would still mess up the caret.

    and more..

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

Sidebar

Related Questions

I have the following div <body> <span style=border:1px solid red; display:inline-block> Some text<br />
I have the following div and paragraphs: <div id=container> <p class=jsavoutput jsavscroll readonly=readonly style=width:225px;
I have following HTML: <div class=olympics style=display: block; position: absolute; left: 250px; top: px;>
I have a webpage including the following div: <div class='book_box'> <table border=0 cellspacing=0> <tr>
I have the following MySQL Query: <div class=box id=settlement1> <? $query = SELECT name,
i have the following code to for xpath query... <div class=buying> <h1 class=parseasinTitle >
I have following div in a page (I can not modify). <div id=:0.control>Click me</div>
I have a following div structure <div id=wrapper> <div id=header> <div id=storeFinder> /* html
How to wrap one div around another? I have following two div ids: #course
i have following code to show div on page <div id=all_users> <div id=user11 userid=11

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.