Replace specific dom element with new content

GhitaB

I have a structure like this:

<div class="foo">
  <div class="bar">
    Some content
  </div>
  Maybe some other content
</div>

I defined a custom plugin for editing this section. And I return the new html content to replace the div.foo.

I set the new content with:

tinyMCE.activeEditor.selection.setContent(html_content);

My custom button related to new plugin is working for both: foo and bar divs. I mean the same behaviour is assigned.

The problem is on save: I want to select the div.foo dom element and replace it with new html_content. So, instead setting the content for current (not sure what) selection how to set the content for a specific dom element in TinyMCE v.3?

(Update: I don't care what the user selected before pressing MyCustomButton, if something inside foo div is selected the full section to be replaced with new content.)

GhitaB

It seems working with just some jQuery code:

var $old_section = $("iframe").contents().find('div.foo').first();
$old_section.replaceWith(html_content);

To be improved: get closest .foo to given selection.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Create new DOM element if a specific height was reached with part of the old content from DOM element before

.replace() arbitrary text with new DOM Element

XSLT - replace specific content of the text() node with a new node

Replace string with DOM element

Replace placeholders in dom element

Replace element value in DOM

Replace specific element value with new strings using conditions xslt 1.0

Replace specific content in file

Load AJAX content for specific element (Pass DOM Element to AJAX callback function)

Replace specific tags in html content with new values using preg_replace_callback

Replace another element content with hovered element content

How to element content into new element

How to replace a DOM element with another?

Replace a DOM element with a different element using CsQuery

Accessing a specific element from the DOM

Checking for specific DOM element in Javascript

Running setTimeout() for a Specific DOM Element

Query to Search for DOM a Specific DOM element

Appending a new dom element in react

Replace specific content from div with html content

How do I check the DOM for a specific element and create a new Vue Instance?

Replace a specific element in a Groovy list

PostgreSQL replace specific html element

How to replace a specific element in a List

How do I replace multiple <br/> tags with a specific element in a new line?

jquery - select an element with specific content

Find and remove element with specific content

How to extract specific parts from the array element that contains HTML code and create a new array with this extracted content?

How to replace the content of an element in a std::map with the content of another element