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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:13:51+00:00 2026-05-11T15:13:51+00:00

I have a problem. I’ve been trying to tackle it for a while now

  • 0

I have a problem. I’ve been trying to tackle it for a while now and I’m ready to explode. Here’s my requirement:
I have an external toolbar (not part of YUI) above the editor that I want to use to insert HTML tags. The user should be able to click a link on the toolbar after which a few things may happen:

  1. If there’s any selected text, this text gets wrapped into an HTML tag
  2. If there’s no selected text, an empty HTML tag is inserted in the editor
  3. Regardless of the scenario, cursor MUST be placed inside the new element, so that when the user enters more text, it resides in the new element

The functionality is very similar to that of pressing ‘B’ or ‘U’ buttons on the editor’s toolbar (now that I’m using this editor, it also does it well :-)). It preserves everything nicely. So far I’m able to do 1 or 2, but not 3. Step 3 is VERY important, because without it, user experience greatly suffers. I really need your assistance to implement it. Below is a simplified version of the method that performs the insertion (just inserting DIV for the sake of simplicity). this._oEditor – local instance of YUI Editor:

this._insertElement = function() { var sSelection = this._oEditor._getSelection(); // Attempt to get selected text from the editor if (sSelection == '') sSelection = '&nbsp;'; // If nothing was selected, insert a non-breaking space  var sNewElt = '<div>' + sSelection + '</div>';  this._oEditor.execCommand('inserthtml', sNewElt);  this._oEditor.focus(); // This gives the editor focus, but places cursor in the beginning! } 

What is it that I must do to place the cursor in the right position? Is it even possible? Also, if there’s a better way of implementing this, I’m all for it. Thank you!

  • 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. 2026-05-11T15:13:52+00:00Added an answer on May 11, 2026 at 3:13 pm

    Here’s complete the solution:

    this._insertElement = function() {    var sSelection = this._oEditor._getSelection();    if (sSelection == '') sSelection = ' ';     var sNewElt = '<div>' + sSelection + '</div>';    this._oEditor.execCommand('inserthtml', sNewElt);    var pos = 1000; //pos determines where to place the cursor. if greater than the length of characters, it will place at the end.   if(this._oEditor.createTextRange) { //IE Specific code         var range = this._oEditor.createTextRange();            range.move('character', pos);            range.select();        } else if(this._oEditor.selectionStart) {  //Works with Firefox and other browsers           this._oEditor.focus();            this._oEditor.setSelectionRange(pos, pos);      }     this._oEditor.focus();  } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 206k
  • Answers 206k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer >>> d = app('Numbers').documents.first() # reference to current top document… May 12, 2026 at 9:13 pm
  • Editorial Team
    Editorial Team added an answer You might consider attacking this with middlware. Specifically using process_request.… May 12, 2026 at 9:13 pm
  • Editorial Team
    Editorial Team added an answer You need to remove the call to NextResult. This method… May 12, 2026 at 9:13 pm

Related Questions

I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a problem. I am coding using VS2008. I am calling webservices from
I have a problem, and was hoping I could rely on some of the
I have a problem related to graph. I am not a computer science grad

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.