- 快速入门
- Explore advanced topics
- Accessibility
- Editor control identifiers
- Annotations
- Editor events
- tinymce-AddOnManager
- Boilerplate content CSS
- Handle asynchronous image uploads
- tinymce-Annotator
- tinymce-FocusEvent
- Configuring callbacks for Comments 2-0
- Keyboard shortcuts
- tinymce-CommandEvent
- tinymce-FocusManager
- tinymce-WindowManager
- Toolbar buttons
- PHP image upload handler
- tinymce-ContentEvent
- tinymce-Formatter
- tinymce-dom-DomQuery
- Create a plugin for TinyMCE
- Security
- tinymce-Editor
- tinymce-NotificationManager
- tinymce-dom-DOMUtils
- Create a skin for TinyMCE
- Usage with module loaders
- tinymce-EditorCommands
- tinymce-Plugin
- tinymce-dom-ScriptLoader
- Create custom notifications
- TinyMCE plugin Yeoman generator
- tinymce-EditorManager
- tinymce-ProgressStateEvent
- tinymce-dom-BookmarkManager
- Editor command identifiers
- tinymce-Formatter
- tinymce-EditorObservable
- tinymce-ResizeEvent
- tinymce-dom-ControlSelection
- tinymce
- tinymce-Env
- tinymce-Shortcuts
- tinymce-dom-DomQuery
- tinymce-Event
- tinymce-Theme
- tinymce-dom-DOMUtils
- tinymce-UndoManager
- tinymce-dom-EventUtils
- tinymce-dom-RangeUtils
- tinymce-dom-ScriptLoader
- tinymce-dom-Selection
- tinymce-html-Schema
- tinymce-dom-Serializer
- tinymce-html-Serializer
- tinymce-util-I18n
- tinymce-dom-TreeWalker
- tinymce-html-Styles
- tinymce-util-JSON
- Cloud deployment of plugins Only
- tinymce-editor-ui-registry
- tinymce-html-Writer
- tinymce-util-JSONRequest
- Version compatibility reference
- Image & file upload options
- tinymce-geom-Rect
- tinymce-util-LocalStorage
- Configuration options reference
- Integration and setup options
- tinymce-html-DomParser
- tinymce-util-Observable
- tinymce-util-Observable
- Advanced editing behaviors
- JWT authentication setup
- tinymce-html-Entities
- tinymce-util-URI
- tinymce-util-Tools
- Content appearance options
- Localization options
- tinymce-html-Node
- tinymce-util-Color
- tinymce-util-XHR
- Content filtering options
- Spelling options
- tinymce-html-SaxParser
- tinymce-util-Delay
- Cloud deployment guide
- Content formatting options
- URL handling options
- tinymce-util-EventDispatcher
- Cloud deployment of editor & plugins
- Contribute to documentation
- Examples & demos
- Specify editor & plugin versions
- Contribute to TinyMCE development
- Basic example
- User interface options
- Case Change
- Checklist plugin
- Classic editor example
- Comments 2-0 Demo
- Custom formats example
- Custom menu item
- HTML5 formats example
- Valid elements example
- Custom toolbar button
- Format Painter
- Live example
- Embed rich media
- Full featured example
- Premium features
- Configure Enhanced Media Embed Server
- Server-side component installation
- Custom toolbar menu button
- Image tools example
- Accessibility checking
- Integrate Enhanced Media Embed Server
- Configure server-side components
- Custom toolbar split button
- Inline editor example
- Advanced source code editing
- Format Painter
- Troubleshoot server-side components
- Tiny Drive
- Local upload
- Case Change
- Get TinyMCE bugs fixed
- Professional support
- Distraction-free editor example
- Page Embed plugin
- Checking links as-you-type
- Mentions
- System requirements
- Basic local file picker
- Permanent Pen plugin
- Check Spelling As-You-Type
- Self-hosted file management
- Commenting & collaboration
- URL conversion example
- Adding custom dictionaries
- Page Embed plugin
- Cloud-based file management
- Checklist plugin
- Paste from Word
- Introduction & getting started
- Permanent Pen Plugin
- Advanced installation choices
- Logo & attribution requirements
- Basic setup
- Customizing the editor UI
- TinyMCE distraction-free editing mode
- Filtering TinyMCE content
- Setup inline editing mode
- Rails integration
- Get Support & FAQ
- Work with plugins to extend TinyMCE
- React integration
- Advanced Code Editor plugin
- Localize TinyMCE
- Integrate with other projects
- TinyMCE for Swing integration
- Advanced List plugin
- Code plugin
- Use multiple TinyMCE instances in a single page
- Angular 2+ integration
- Vue integration
- Anchor plugin
- Code Sample plugin
- Check spelling in TinyMCE
- Angular 1 integration
- WordPress integration
- Autolink plugin
- Color Picker plugin
- System requirements
- Bootstrap integration
- Migrating from TinyMCE 4-x to TinyMCE 5-0-
- Autoresize plugin
- Comments 2-0
- Uploading images and files
- Dojo integration
- TinyMCE Mobile
- Autosave plugin
- TinyMCE classic editing mode
- jQuery integration
- BBCode plugin
- Context Menu plugin
- KnockoutJS integration
- Add plugins to TinyMCE
- Case Change
- Directionality plugin
- Accessibility Checker plugin
- Character Map plugin
- Drive plugin
- Checklist plugin
- Emoticons plugin
- Format Painter
- Full Page plugin
- Full Screen plugin
- Link Checker plugin
- Help plugin
- Lists plugin
- Paste plugin
- Horizontal Rule plugin
- Media plugin
- Permanent Pen Plugin
- Table plugin
- Image plugin
- Enhanced Media Embed plugin
- PowerPaste plugin
- Template plugin
- User interface components
- Image Tools plugin
- Mentions plugin
- Preview plugin
- Text Color plugin
- Autocompleter
- Import CSS plugin
- MoxieManager plugin
- Print plugin
- Text Pattern plugin
- Context forms
- Insert Date/Time plugin
- Nonbreaking Space plugin
- Quick Toolbar plugin
- Spell Checker Pro plugin
- Context menu
- Legacy Output plugin
- Noneditable plugin
- Save plugin
- Table of Contents plugin
- Context toolbar
- Link plugin
- Page Break plugin
- Search and Replace plugin
- Visual Blocks plugin
- Custom sidebar
- Page Embed plugin
- Spell Checker plugin
- Visual Characters plugin
- Dialog
- Tab Focus plugin
- Word Count plugin
- Dialog components
- Quick start
- Custom menu items
- Toolbar buttons
- Types of toolbar buttons
tinymce-dom-DOMUtils
Examples
// Add a class to an element by id in the page
tinymce.DOM.addClass('someid', 'someclass');
// Add a class to an element by id inside the editor
tinymce.activeEditor.dom.addClass('someid', 'someclass');
Properties
name | type | summary | defined by |
---|---|---|---|
DOM | tinymce.dom.DOMUtils | Instance of DOMUtils for the current document. | tinymce.dom.DOMUtils |
Constructors
name | summary | defined by |
---|---|---|
DOMUtils() | Constructs a new DOMUtils instance. Consult the Wiki for more details on settings etc for this class. | tinymce.dom.DOMUtils |
Methods
name | summary | defined by |
---|---|---|
add() | Adds the specified element to another element or elements. | tinymce.dom.DOMUtils |
addClass() | Adds a class to the specified element or elements. | tinymce.dom.DOMUtils |
addStyle() | Adds a style element at the top of the document with the specified cssText content. | tinymce.dom.DOMUtils |
bind() | Adds an event handler to the specified object. | tinymce.dom.DOMUtils |
create() | Creates a new element. | tinymce.dom.DOMUtils |
createFragment() | Creates a document fragment out of the specified HTML string. | tinymce.dom.DOMUtils |
createHTML() | Creates HTML string for element. The element will be closed unless an empty inner HTML string is passed in. | tinymce.dom.DOMUtils |
createRng() | Creates a new DOM Range object. This will use the native DOM Range API if it's available. If it's not, it will fall back to the custom TinyMCE implementation. | tinymce.dom.DOMUtils |
decode() | Entity decodes a string. This method decodes any HTML entities, such as å. | tinymce.dom.DOMUtils |
destroy() | Destroys all internal references to the DOM to solve IE leak issues. | tinymce.dom.DOMUtils |
encode() | Entity encodes a string. This method encodes the most common entities, such as "&. | tinymce.dom.DOMUtils |
findCommonAncestor() | Find the common ancestor of two elements. This is a shorter method than using the DOM Range logic. | tinymce.dom.DOMUtils |
fire() | Fires the specified event name with object on target. | tinymce.dom.DOMUtils |
get() | Returns the specified element by ID or the input element if it isn't a string. | tinymce.dom.DOMUtils |
getAttrib() | Returns the specified attribute by name. | tinymce.dom.DOMUtils |
getAttribs() | Returns a NodeList with attributes for the element. | tinymce.dom.DOMUtils |
getNext() | Returns the next node that matches selector or function | tinymce.dom.DOMUtils |
getOuterHTML() | Returns the outer HTML of an element. | tinymce.dom.DOMUtils |
getParent() | Returns a node by the specified selector function. This function will loop through all parent nodes and call the specified function for each node. If the function then returns true indicating that it has found what it was looking for, the loop execution will then end and the node it found will be returned. | tinymce.dom.DOMUtils |
getParents() | Returns a node list of all parents matching the specified selector function or pattern. If the function then returns true indicating that it has found what it was looking for and that node will be collected. | tinymce.dom.DOMUtils |
getPos() | Returns the absolute x, y position of a node. The position will be returned in an object with x, y fields. | tinymce.dom.DOMUtils |
getPrev() | Returns the previous node that matches selector or function | tinymce.dom.DOMUtils |
getRect() | Returns the rectangle for a specific element. | tinymce.dom.DOMUtils |
getRoot() | Returns the root node of the document. This is normally the body but might be a DIV. Parents like getParent will not go above the point of this root node. | tinymce.dom.DOMUtils |
getSize() | Returns the size dimensions of the specified element. | tinymce.dom.DOMUtils |
getStyle() | Returns the current style or runtime/computed value of an element. | tinymce.dom.DOMUtils |
getViewPort() | Returns the viewport of the window. | tinymce.dom.DOMUtils |
hasClass() | Returns true if the specified element has the specified class. | tinymce.dom.DOMUtils |
hide() | Hides the specified element(s) by ID by setting the "display" style. | tinymce.dom.DOMUtils |
insertAfter() | Inserts an element after the reference element. | tinymce.dom.DOMUtils |
is() | Returns true/false if the specified element matches the specified css pattern. | tinymce.dom.DOMUtils |
isBlock() | Returns true/false if the specified element is a block element or not. | tinymce.dom.DOMUtils |
isEmpty() | Returns true/false if the specified node is to be considered empty or not. | tinymce.dom.DOMUtils |
isHidden() | Returns true/false if the element is hidden or not by checking the "display" style. | tinymce.dom.DOMUtils |
loadCSS() | Imports/loads the specified CSS file into the document bound to the class. | tinymce.dom.DOMUtils |
nodeIndex() | Returns the index of the specified node within its parent. | tinymce.dom.DOMUtils |
parseStyle() | Parses the specified style value into an object collection. This parser will also merge and remove any redundant items that browsers might have added. It will also convert non-hex colors to hex values. Urls inside the styles will also be converted to absolute/relative based on settings. | tinymce.dom.DOMUtils |
remove() | Removes/deletes the specified element(s) from the DOM. | tinymce.dom.DOMUtils |
removeAllAttribs() | Removes all attributes from an element or elements. | tinymce.dom.DOMUtils |
removeClass() | Removes a class from the specified element or elements. | tinymce.dom.DOMUtils |
rename() | Renames the specified element and keeps its attributes and children. | tinymce.dom.DOMUtils |
replace() | Replaces the specified element or elements with the new element specified. The new element will be cloned if multiple input elements are passed in. | tinymce.dom.DOMUtils |
run() | Executes the specified function on the element by id or dom element node or array of elements/id. | tinymce.dom.DOMUtils |
select() | Selects specific elements by a CSS level 3 pattern. For example "div#a1 p.test". This function is optimized for the most common patterns needed in TinyMCE but it also performs well enough on more complex patterns. | tinymce.dom.DOMUtils |
serializeStyle() | Serializes the specified style object into a string. | tinymce.dom.DOMUtils |
setAttrib() | Sets the specified attribute of an element or elements. | tinymce.dom.DOMUtils |
setAttribs() | Sets two or more specified attributes of an element or elements. | tinymce.dom.DOMUtils |
setHTML() | Sets the specified HTML content inside the element or elements. The HTML will first be processed. This means URLs will get converted, hex color values fixed etc. Check processHTML for details. | tinymce.dom.DOMUtils |
setOuterHTML() | Sets the specified outer HTML on an element or elements. | tinymce.dom.DOMUtils |
setStyle() | Sets the CSS style value on a HTML element. The name can be a camelcase string or the CSS style name like background-color. | tinymce.dom.DOMUtils |
setStyles() | Sets multiple styles on the specified element(s). | tinymce.dom.DOMUtils |
show() | Shows the specified element(s) by ID by setting the "display" style. | tinymce.dom.DOMUtils |
split() | Splits an element into two new elements and places the specified split element or elements between the new ones. For example splitting the paragraph at the bold element in this example abcabc123 would produceabc abc123 . | tinymce.dom.DOMUtils |
toHex() | Parses the specified RGB color value and returns a hex version of that color. | tinymce.dom.DOMUtils |
toggleClass() | Toggles the specified class on/off. | tinymce.dom.DOMUtils |
unbind() | Removes the specified event handler by name and function from an element or collection of elements. | tinymce.dom.DOMUtils |
uniqueId() | Returns a unique id. This can be useful when generating elements on the fly. This method will not check if the element already exists. | tinymce.dom.DOMUtils |
Constructors
DOMUtils
public constructor function DOMUtils(doc:Document, settings:settings)Constructs a new DOMUtils instance. Consult the Wiki for more details on settings etc for this class.
Parameters
- doc (Document) - Document reference to bind the utility class to.
- settings (settings) - Optional settings collection.
Methods
add
add(parentElm:String, name:String, attrs:Object, html:String, create:Boolean):Element, ArrayAdds the specified element to another element or elements.
Examples
// Adds a new paragraph to the end of the active editor
tinymce.activeEditor.dom.add(tinymce.activeEditor.getBody(), 'p', {title: 'my title'}, 'Some content');
Parameters
- parentElm (String) - Element id string, DOM node element or array of ids or elements to add to.
- name (String) - Name of new element to add or existing element to add.
- attrs (Object) - Optional object collection with arguments to add to the new element(s).
- html (String) - Optional inner HTML contents to add for each element.
- create (Boolean) - Optional flag if the element should be created or added.
Return value
- Element - Element that got created, or an array of created elements if multiple input elements were passed in.
- Array - Element that got created, or an array of created elements if multiple input elements were passed in.
addClass
addClass(elm:String, cls:String):String, ArrayAdds a class to the specified element or elements.
Examples
// Adds a class to all paragraphs in the active editor
tinymce.activeEditor.dom.addClass(tinymce.activeEditor.dom.select('p'), 'myclass');
// Adds a class to a specific element in the current page
tinymce.DOM.addClass('mydiv', 'myclass');
Parameters
- elm (String) - Element ID string or DOM element or array with elements or IDs.
- cls (String) - Class name to add to each element.
Return value
- String - String with new class value or array with new class values for all elements.
- Array - String with new class value or array with new class values for all elements.
addStyle
addStyle(cssText:String)Adds a style element at the top of the document with the specified cssText content.
Parameters
- cssText (String) - CSS Text style to add to top of head of document.
bind
bind(target:Element, name:String, func:function, scope:Object):functionAdds an event handler to the specified object.
Parameters
- target (Element) - Target element to bind events to. handler to or an array of elements/ids/documents.
- name (String) - Name of event handler to add, for example: click.
- func (function) - Function to execute when the event occurs.
- scope (Object) - Optional scope to execute the function in.
Return value
- function - Function callback handler the same as the one passed in.
create
create(name:String, attrs:Object, html:String):ElementCreates a new element.
Examples
// Adds an element where the caret/selection is in the active editor
var el = tinymce.activeEditor.dom.create('div', {id: 'test', 'class': 'myclass'}, 'some content');
tinymce.activeEditor.selection.setNode(el);
Parameters
- name (String) - Name of new element.
- attrs (Object) - Optional object name/value collection with element attributes.
- html (String) - Optional HTML string to set as inner HTML of the element.
Return value
- Element - HTML DOM node element that got created.
createFragment
createFragment(html:String):DocumentFragmentCreates a document fragment out of the specified HTML string.
Parameters
- html (String) - Html string to create fragment from.
Return value
- DocumentFragment - Document fragment node.
createHTML
createHTML(name:String, attrs:Object, html:String):StringCreates HTML string for element. The element will be closed unless an empty inner HTML string is passed in.
Examples
// Creates a html chunk and inserts it at the current selection/caret location
tinymce.activeEditor.selection.setContent(tinymce.activeEditor.dom.createHTML('a', {href: 'test.html'}, 'some line'));
Parameters
- name (String) - Name of new element.
- attrs (Object) - Optional object name/value collection with element attributes.
- html (String) - Optional HTML string to set as inner HTML of the element.
Return value
- String - String with new HTML element, for example: test.
createRng
createRng():DOMRangeCreates a new DOM Range object. This will use the native DOM Range API if it's available. If it's not, it will fall back to the custom TinyMCE implementation.
Examples
var rng = tinymce.DOM.createRng();
alert(rng.startContainer + "," + rng.startOffset);
Return value
- DOMRange - DOM Range object.
decode
decode(s:String):StringEntity decodes a string. This method decodes any HTML entities, such as å.
Parameters
- s (String) - String to decode entities on.
Return value
- String - Entity decoded string.
destroy
destroy()Destroys all internal references to the DOM to solve IE leak issues.
encode
encode(text:String):StringEntity encodes a string. This method encodes the most common entities, such as "&.
Parameters
- text (String) - String to encode with entities.
Return value
- String - Entity encoded string.
findCommonAncestor
findCommonAncestor(a:Element, b:Element):ElementFind the common ancestor of two elements. This is a shorter method than using the DOM Range logic.
Parameters
- a (Element) - Element to find common ancestor of.
- b (Element) - Element to find common ancestor of.
Return value
- Element - Common ancestor element of the two input elements.
fire
fire(target:Node, name:String, evt:Object):EventFires the specified event name with object on target.
Parameters
- target (Node) - Target element or object to fire event on.
- name (String) - Name of the event to fire.
- evt (Object) - Event object to send.
Return value
- Event - Event object.
get
get(n:String):ElementReturns the specified element by ID or the input element if it isn't a string.
Parameters
- n (String) - Element id to look for or element to just pass though.
Return value
- Element - Element matching the specified id or null if it wasn't found.
getAttrib
getAttrib(elm:String, name:String, defaultVal:String):StringReturns the specified attribute by name.
Parameters
- elm (String) - Element string id or DOM element to get attribute from.
- name (String) - Name of attribute to get.
- defaultVal (String) - Optional default value to return if the attribute didn't exist.
Return value
- String - Attribute value string, default value or null if the attribute wasn't found.
getAttribs
getAttribs(elm:HTMLElement):NodeListReturns a NodeList with attributes for the element.
Parameters
- elm (HTMLElement) - Element node or string id to get attributes from.
Return value
- NodeList - NodeList with attributes.
getNext
getNext(node:Node, selector:String):NodeReturns the next node that matches selector or function
Parameters
- node (Node) - Node to find siblings from.
- selector (String) - Selector CSS expression or function.
Return value
- Node - Next node item matching the selector or null if it wasn't found.
getOuterHTML
getOuterHTML(elm:String):StringReturns the outer HTML of an element.
Examples
tinymce.DOM.getOuterHTML(editorElement);
tinymce.activeEditor.getOuterHTML(tinymce.activeEditor.getBody());
Parameters
- elm (String) - Element ID or element object to get outer HTML from.
Return value
- String - Outer HTML string.
getParent
getParent(node:Node, selector:function, root:Node):NodeReturns a node by the specified selector function. This function will loop through all parent nodes and call the specified function for each node. If the function then returns true indicating that it has found what it was looking for, the loop execution will then end and the node it found will be returned.
Parameters
- node (Node) - DOM node to search parents on or ID string.
- selector (function) - Selection function or CSS selector to execute on each node.
- root (Node) - Optional root element, never go beyond this point.
Return value
- Node - DOM Node or null if it wasn't found.
getParents
getParents(node:Node, selector:function, root:Node):ArrayReturns a node list of all parents matching the specified selector function or pattern. If the function then returns true indicating that it has found what it was looking for and that node will be collected.
Parameters
- node (Node) - DOM node to search parents on or ID string.
- selector (function) - Selection function to execute on each node or CSS pattern.
- root (Node) - Optional root element, never go beyond this point.
Return value
- Array - Array of nodes or null if it wasn't found.
getPos
getPos(elm:Element, rootElm:Element):objectReturns the absolute x, y position of a node. The position will be returned in an object with x, y fields.
Parameters
- elm (Element) - HTML element or element id to get x, y position from.
- rootElm (Element) - Optional root element to stop calculations at.
Return value
- object - Absolute position of the specified element object with x, y fields.
getPrev
getPrev(node:Node, selector:String):NodeReturns the previous node that matches selector or function
Parameters
- node (Node) - Node to find siblings from.
- selector (String) - Selector CSS expression or function.
Return value
- Node - Previous node item matching the selector or null if it wasn't found.
getRect
getRect(elm:Element):objectReturns the rectangle for a specific element.
Parameters
- elm (Element) - Element object or element ID to get rectangle from.
Return value
- object - Rectangle for specified element object with x, y, w, h fields.
getRoot
getRoot():ElementReturns the root node of the document. This is normally the body but might be a DIV. Parents like getParent will not go above the point of this root node.
Return value
- Element - Root element for the utility class.
getSize
getSize(elm:Element):objectReturns the size dimensions of the specified element.
Parameters
- elm (Element) - Element object or element ID to get rectangle from.
Return value
- object - Rectangle for specified element object with w, h fields.
getStyle
getStyle(elm:String, name:String, computed:Boolean):StringReturns the current style or runtime/computed value of an element.
Parameters
- elm (String) - HTML element or element id string to get style from.
- name (String) - Style name to return.
- computed (Boolean) - Computed style.
Return value
- String - Current style or computed style value of an element.
getViewPort
getViewPort(win:Window):ObjectReturns the viewport of the window.
Parameters
- win (Window) - Optional window to get viewport of.
Return value
- Object - Viewport object with fields x, y, w and h.
hasClass
hasClass(elm:String, cls:String):BooleanReturns true if the specified element has the specified class.
Parameters
- elm (String) - HTML element or element id string to check CSS class on.
- cls (String) - CSS class to check for.
Return value
- Boolean - true/false if the specified element has the specified class.
hide
hide(elm:String)Hides the specified element(s) by ID by setting the "display" style.
Examples
// Hides an element by id in the document
tinymce.DOM.hide('myid');
Parameters
- elm (String) - ID of DOM element or DOM element or array with elements or IDs to hide.
insertAfter
insertAfter(node:Element, referenceNode:Element):Element, ArrayInserts an element after the reference element.
Parameters
- node (Element) - Element to insert after the reference.
- referenceNode (Element) - Reference element, element id or array of elements to insert after.
Return value
- Element - Element that got added or an array with elements.
- Array - Element that got added or an array with elements.
is
is(elm:Node, selector:String)Returns true/false if the specified element matches the specified css pattern.
Parameters
- elm (Node) - DOM node to match or an array of nodes to match.
- selector (String) - CSS pattern to match the element against.
isBlock
isBlock(node:Node):BooleanReturns true/false if the specified element is a block element or not.
Parameters
- node (Node) - Element/Node to check.
Return value
- Boolean - True/False state if the node is a block element or not.
isEmpty
isEmpty(elements:Object):BooleanReturns true/false if the specified node is to be considered empty or not.
Examples
tinymce.DOM.isEmpty(node, {img: true});
Parameters
- elements (Object) - Optional name/value object with elements that are automatically treated as non-empty elements.
Return value
- Boolean - true/false if the node is empty or not.
isHidden
isHidden(elm:String):BooleanReturns true/false if the element is hidden or not by checking the "display" style.
Parameters
- elm (String) - Id or element to check display state on.
Return value
- Boolean - true/false if the element is hidden or not.
loadCSS
loadCSS(url:String)Imports/loads the specified CSS file into the document bound to the class.
Examples
// Loads a CSS file dynamically into the current document
tinymce.DOM.loadCSS('somepath/some.css');
// Loads a CSS file into the currently active editor instance
tinymce.activeEditor.dom.loadCSS('somepath/some.css');
// Loads a CSS file into an editor instance by id
tinymce.get('someid').dom.loadCSS('somepath/some.css');
// Loads multiple CSS files into the current document
tinymce.DOM.loadCSS('somepath/some.css,somepath/someother.css');
Parameters
- url (String) - URL to CSS file to load.
nodeIndex
nodeIndex(node:Node, normalized:boolean):NumberReturns the index of the specified node within its parent.
Parameters
- node (Node) - Node to look for.
- normalized (boolean) - Optional true/false state if the index is what it would be after a normalization.
Return value
- Number - Index of the specified node.
parseStyle
parseStyle(cssText:String):ObjectParses the specified style value into an object collection. This parser will also merge and remove any redundant items that browsers might have added. It will also convert non-hex colors to hex values. Urls inside the styles will also be converted to absolute/relative based on settings.
Parameters
- cssText (String) - Style value to parse, for example: border:1px solid red;.
Return value
- Object - Object representation of that style, for example: {border: '1px solid red'}
remove
remove(node:String, keepChildren:Boolean):Element, ArrayRemoves/deletes the specified element(s) from the DOM.
Examples
// Removes all paragraphs in the active editor
tinymce.activeEditor.dom.remove(tinymce.activeEditor.dom.select('p'));
// Removes an element by id in the document
tinymce.DOM.remove('mydiv');
Parameters
- node (String) - ID of element or DOM element object or array containing multiple elements/ids.
- keepChildren (Boolean) - Optional state to keep children or not. If set to true all children will be placed at the location of the removed element.
Return value
- Element - HTML DOM element that got removed, or an array of removed elements if multiple input elements were passed in.
- Array - HTML DOM element that got removed, or an array of removed elements if multiple input elements were passed in.
removeAllAttribs
removeAllAttribs(e:Element)Removes all attributes from an element or elements.
Parameters
- e (Element) - DOM element, element id string or array of elements/ids to remove attributes from.
removeClass
removeClass(elm:String, cls:String):String, ArrayRemoves a class from the specified element or elements.
Examples
// Removes a class from all paragraphs in the active editor
tinymce.activeEditor.dom.removeClass(tinymce.activeEditor.dom.select('p'), 'myclass');
// Removes a class from a specific element in the current page
tinymce.DOM.removeClass('mydiv', 'myclass');
Parameters
- elm (String) - Element ID string or DOM element or array with elements or IDs.
- cls (String) - Class name to remove from each element.
Return value
- String - String of remaining class name(s), or an array of strings if multiple input elements were passed in.
- Array - String of remaining class name(s), or an array of strings if multiple input elements were passed in.
rename
rename(elm:Element, name:String):ElementRenames the specified element and keeps its attributes and children.
Parameters
- elm (Element) - Element to rename.
- name (String) - Name of the new element.
Return value
- Element - New element or the old element if it needed renaming.
replace
replace(newElm:Element, oldElm:Element, keepChildren:Boolean)Replaces the specified element or elements with the new element specified. The new element will be cloned if multiple input elements are passed in.
Parameters
- newElm (Element) - New element to replace old ones with.
- oldElm (Element) - Element DOM node, element id or array of elements or ids to replace.
- keepChildren (Boolean) - Optional keep children state, if set to true child nodes from the old object will be added to new ones.
run
run(elm:String, func:function, scope:Object):Object, ArrayExecutes the specified function on the element by id or dom element node or array of elements/id.
Parameters
- elm (String) - ID or DOM element object or array with ids or elements.
- func (function) - Function to execute for each item.
- scope (Object) - Optional scope to execute the function in.
Return value
- Object - Single object, or an array of objects if multiple input elements were passed in.
- Array - Single object, or an array of objects if multiple input elements were passed in.
select
select(selector:String, scope:Object):ArraySelects specific elements by a CSS level 3 pattern. For example "div#a1 p.test". This function is optimized for the most common patterns needed in TinyMCE but it also performs well enough on more complex patterns.
Examples
// Adds a class to all paragraphs in the currently active editor
tinymce.activeEditor.dom.addClass(tinymce.activeEditor.dom.select('p'), 'someclass');
// Adds a class to all spans that have the test class in the currently active editor
tinymce.activeEditor.dom.addClass(tinymce.activeEditor.dom.select('span.test'), 'someclass')
Parameters
- selector (String) - CSS level 3 pattern to select/find elements by.
- scope (Object) - Optional root element/scope element to search in.
Return value
- Array - Array with all matched elements.
serializeStyle
serializeStyle(styles:Object, name:String):StringSerializes the specified style object into a string.
Parameters
- styles (Object) - Object to serialize as string, for example: {border: '1px solid red'}
- name (String) - Optional element name.
Return value
- String - String representation of the style object, for example: border: 1px solid red.
setAttrib
setAttrib(elm:Element, name:String, value:String)Sets the specified attribute of an element or elements.
Examples
// Sets class attribute on all paragraphs in the active editor
tinymce.activeEditor.dom.setAttrib(tinymce.activeEditor.dom.select('p'), 'class', 'myclass');
// Sets class attribute on a specific element in the current page
tinymce.dom.setAttrib('mydiv', 'class', 'myclass');
Parameters
- elm (Element) - DOM element, element id string or array of elements/ids to set attribute on.
- name (String) - Name of attribute to set.
- value (String) - Value to set on the attribute - if this value is falsy like null, 0 or '' it will remove the attribute instead.
setAttribs
setAttribs(elm:Element, attrs:Object)Sets two or more specified attributes of an element or elements.
Examples
// Sets class and title attributes on all paragraphs in the active editor
tinymce.activeEditor.dom.setAttribs(tinymce.activeEditor.dom.select('p'), {'class': 'myclass', title: 'some title'});
// Sets class and title attributes on a specific element in the current page
tinymce.DOM.setAttribs('mydiv', {'class': 'myclass', title: 'some title'});
Parameters
- elm (Element) - DOM element, element id string or array of elements/ids to set attributes on.
- attrs (Object) - Name/Value collection of attribute items to add to the element(s).
setHTML
setHTML(elm:Element, html:String)Sets the specified HTML content inside the element or elements. The HTML will first be processed. This means URLs will get converted, hex color values fixed etc. Check processHTML for details.
Examples
// Sets the inner HTML of all paragraphs in the active editor
tinymce.activeEditor.dom.setHTML(tinymce.activeEditor.dom.select('p'), 'some inner html');
// Sets the inner HTML of an element by id in the document
tinymce.DOM.setHTML('mydiv', 'some inner html');
Parameters
- elm (Element) - DOM element, element id string or array of elements/ids to set HTML inside of.
- html (String) - HTML content to set as inner HTML of the element.
setOuterHTML
setOuterHTML(elm:Element, html:Object)Sets the specified outer HTML on an element or elements.
Examples
// Sets the outer HTML of all paragraphs in the active editor
tinymce.activeEditor.dom.setOuterHTML(tinymce.activeEditor.dom.select('p'), '<div>some html</div>');
// Sets the outer HTML of an element by id in the document
tinymce.DOM.setOuterHTML('mydiv', '<div>some html</div>');
Parameters
- elm (Element) - DOM element, element id string or array of elements/ids to set outer HTML on.
- html (Object) - HTML code to set as outer value for the element.
setStyle
setStyle(elm:String, name:String, value:String)Sets the CSS style value on a HTML element. The name can be a camelcase string or the CSS style name like background-color.
Examples
// Sets a style value on all paragraphs in the currently active editor
tinymce.activeEditor.dom.setStyle(tinymce.activeEditor.dom.select('p'), 'background-color', 'red');
// Sets a style value to an element by id in the current document
tinymce.DOM.setStyle('mydiv', 'background-color', 'red');
Parameters
- elm (String) - HTML element/Array of elements to set CSS style value on.
- name (String) - Name of the style value to set.
- value (String) - Value to set on the style.
setStyles
setStyles(elm:Element, styles:Object)Sets multiple styles on the specified element(s).
Examples
// Sets styles on all paragraphs in the currently active editor
tinymce.activeEditor.dom.setStyles(tinymce.activeEditor.dom.select('p'), {'background-color': 'red', 'color': 'green'});
// Sets styles to an element by id in the current document
tinymce.DOM.setStyles('mydiv', {'background-color': 'red', 'color': 'green'});
Parameters
- elm (Element) - DOM element, element id string or array of elements/ids to set styles on.
- styles (Object) - Name/Value collection of style items to add to the element(s).
show
show(elm:String)Shows the specified element(s) by ID by setting the "display" style.
Parameters
- elm (String) - ID of DOM element or DOM element or array with elements or IDs to show.
split
split(parentElm:Element, splitElm:Element, replacementElm:Element):ElementSplits an element into two new elements and places the specified split element or elements between the new ones. For example splitting the paragraph at the bold element in this example
abcabc123
would produceabc
abc123
.Parameters
- parentElm (Element) - Parent element to split.
- splitElm (Element) - Element to split at.
- replacementElm (Element) - Optional replacement element to replace the split element with.
Return value
- Element - Returns the split element or the replacement element if that is specified.
toHex
toHex(rgbVal:String):StringParses the specified RGB color value and returns a hex version of that color.
Parameters
- rgbVal (String) - RGB string value like rgb(1,2,3)
Return value
- String - Hex version of that RGB value like #FF00FF.
toggleClass
toggleClass(elm:Element, cls:[type], state:[type])Toggles the specified class on/off.
Parameters
- elm (Element) - Element to toggle class on.
- cls ([type]) - Class to toggle on/off.
- state ([type]) - Optional state to set.
unbind
unbind(target:Element, name:String, func:function):bool, ArrayRemoves the specified event handler by name and function from an element or collection of elements.
Parameters
- target (Element) - Target element to unbind events on.
- name (String) - Event handler name, for example: "click"
- func (function) - Function to remove.
Return value
- bool - Bool state of true if the handler was removed, or an array of states if multiple input elements were passed in.
- Array - Bool state of true if the handler was removed, or an array of states if multiple input elements were passed in.
uniqueId
uniqueId(prefix:String):StringReturns a unique id. This can be useful when generating elements on the fly. This method will not check if the element already exists.
Parameters
- prefix (String) - Optional prefix to add in front of all ids - defaults to "mce_".
Return value
- String - Unique id.
Can't find what you're looking for? Let us know.
Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论