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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:05:56+00:00 2026-05-25T22:05:56+00:00

I found javascript code that allows me to add html tags around text that

  • 0

I found javascript code that allows me to add html tags around text that I have highlighted in the textarea field:

    <textarea id="myArea" cols="30" spellcheck="false">Select some text within this field.</textarea>
        <button onclick="ModifySelection ()">Modify the current selection</button>

<script>
      function ModifySelection () {
                var textarea = document.getElementById("myArea");
          if('selectionStart' in textarea){
          if (textarea.selectionStart != textarea.selectionEnd) {
                        var newText = textarea.value.substring (0, textarea.selectionStart) + 
                            "[start]" + textarea.value.substring  (textarea.selectionStart, textarea.selectionEnd) + "[end]" +
                            textarea.value.substring (textarea.selectionEnd);
                        textarea.value = newText;
                    }
                }
    }
</script>

My questions pertain to this line, if('selectionStart' in textarea){:

  1. What does the line mean exactly?
  2. Why does selectionStart have to be in quotes?
  3. selectionStart is usually appended to an object like
    "textarea"(textarea.selectionStart), how is it possible to refer
    to
    it by itself?
  4. Is If(X in Y){} standard javascript syntax or does it work
    specifically forselectionStart?

note: I’m testing this in jsfiddle

  • 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-25T22:05:57+00:00Added an answer on May 25, 2026 at 10:05 pm
    1. if('selectionStart' in textarea) is feature testing – it checks whether the textarea object has a selectionStart property.

    2. It needs to be in quotes as otherwise it would be interpreted as a variable (which may or may not exist in the current context).

    3. It depends on the browser and what version of HTML is supported and rendered.

    4. Yes it is normal javascript syntax. It is used to test if the specified property is in the object. See in on MDN.

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

Sidebar

Related Questions

I have some JavaScript code that dynamically injects an iframe in a given HTML
I code primarily in javascript and in vb.net. I've found that if I can
While debugging a javascript code that uses jQuery I found the following code: [0,
I have some JavaScript code that is supposed to run on document.ready but I
I have a custom control that is made up of a text field and
I have a userscript (read: my Javascript on someone else's site) that allows users
I have this piece of code: <script language=javascript type=text/jscript> document.write(<img src='http://dm.leadgenesys.com/jpgp.lgt?en=P.........TP_Q=&amp;ur=' + escape(document.referrer) +
I have found a JavaScript gallery . When I view the JavaScript code, I
The following javascript code concatenates the matches found by a regular expression. The regular
I look for tool which can compress JavaScript source code. I found some web

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.