How can I get the text style from window.selection()?


Tags: javascript,html,css,dom,selection

Problem :

I'm trying to get the css style of the text selection when user select only 1 row.

This is my code which works for multiple lines selection case:

var selectedDivs = window.selection().getRangeAt(0).cloneContent().children
// Then I can get css style from selectedDivs 

But for single line selection, the selectedDivs is always []. How can I get the css style in this case? I've tried startContainer & endContainer of range but it didn't work.



Solution :

parentNode of the startContainer should give you what you need.

window.getSelection().getRangeAt(0).startContainer.parentNode

    CSS Howto..

    how to create bar code like in a horizontal line using css (For Email)

    How to remove a CSS class from a Wicket component?

    how to load css for a div?

    How do I use “:nth-of-type” to select an element after the element is updated by jQuery?

    How to use CSS to create a matrix of cells, and not use HTML tags at all

    how to route to css/js files in mvc.net

    CSS, how to create a label width of the longest containing text?

    How to reference an embedded image from CSS?

    How can I align my search button to the right?

    How to use JavaScript OnResize with delay or less processing intensive

    how to give top property define in css for chrome or firefox

    How to change tinymce scrollbar color?

    How to expand my CSS3 menu and reduce its width

    How to apply table css to this structure?

    How to use ExtJS stripeRows with RowExpander plugin in IE8

    Django + Mac osx how to use less css?

    How to overwrite Twitter Bootstrap navbar-inner class

    How with JQuery cause Hover on diffrent element than mouse is currently on top of

    How to make line-through wider/bigger than text/element using CSS

    How do I put several elements on the second row in a div

    How to design multiple time clock wise rotation of a image in css

    How to make my asp chart scrollable in the x direction

    How to expand and
  • to fit the width of the
      using css? (or even jquery)
  • How can I put a inside of an ? [duplicate]

    How to use custom CSS to change the distance between the header and top of the page/where the page starts? [closed]

    How to set outline without using CSS outline property?

    How to fix the alignment of my sub-menu

    How to crop a rectangular image into a square using CSS?

    How to set the RadioButton icon style to nothing in CSS (in Flex 3)?

    How to set background-image to take remaining section of the page in semantic-ui