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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:39:32+00:00 2026-05-18T05:39:32+00:00

I want to check the node of the selected text. If it is span,

  • 0

I want to check the node of the selected text. If it is span, another function will edit the classes applied to it. If it is same as the parent node, then the code will wrap the selection in span and set its styles. The problem here I’m facing is, how to determine, if user has selected the whole text inside the editor or only some text. If user selects the whole text, I want to apply the styles to the parent node instead of adding a new span and styles to it. Below is my code –

  var ed=tinyMCE.getInstanceById('textAreaId'); 
  var sel = ed.selection.getContent();

  if(trim(sel)!="") {
  //get the node of the selection
  var thisNode=tinyMCE.activeEditor.selection.getStart().nodeName;   
 ed_Property=propertyName;
 ed_PropertyVal=propertyValue;
 //get the root node inside editor
 var parentNode=tinyMCE.activeEditor.getBody().firstChild.nodeName;
 if(thisNode=="SPAN") {
 nodeclass=$(tinyMCE.activeEditor.selection.getNode()).attr('class');    
//edit span properties
editSpanProperties(nodeclass,propertyName,propertyValue);

}
 else if(thisNode==parentNode) {
  var elmType="span";
  var Spanid1=createSpanId(targetToStyle,elmType);
  Spanid=targetToStyle+"_"+elmType+"_"+Spanid1;
  var strStyle=ed_Property+":"+ed_PropertyVal;
//wrap selection in a span
sel = "<span id='"+Spanid+"' style='"+strStyle+"'>" + sel + "</span>";
//set content    
ed.selection.setContent(sel);
//retain the selection
  ed.selection.select(ed.dom.select('#'+Spanid)[0],false);

}

  else {

     //here I need to check if user has selected whole text and set properties
    setStylesOnEditor(templateSection,propertyName,propertyValue);    
  }//if ends


  }
   else if(trim(sel)=="")   {
   alert('No text selected');
  }
  • 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-18T05:39:32+00:00Added an answer on May 18, 2026 at 5:39 am

    how to determine, if user has selected
    the whole text inside the editor or
    only some text.

    You need to compare the selected text with the editors content:

    var content_editor = $(ed.getBody()).text();
    
    var content_selection = ed.selection.getContent({format : 'text'});
    
    // now compare both either characterwise or as whole string, 
    // you might need to strip whitespace characters from the strings!
    // and do what you want to do in each case
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check the parent of current node is root node or not
This is the feature i want to implement: check a tree node by click
I want to check a Column value when update.If its match insert into another
I want to check if the node <Type> is either Debit or Credit so
I rendered a check box node tree. The renderer renders the parent nodes with
I want to check given node is exist or not in *.xml file. I
I want to check whether an a node contains the word B. If so,
I have this xml, I want to check the existence of price node if
Private Function Check(ByVal mytreeNode As TreeNodeCollection) As Boolean For Each node As TreeNode In
I want to check if a treenode is exists and if exists then add

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.