[Vuejs]-How to position a caret in a contenteditable div while ignoring the HTML tags?

2👍

You may need to search those nodes inside the div recursively:

function findTextNode(node) {
  const childNodes = node.childNodes;
  if (childNodes.length > 0) {
    for(let i=0; i<childNodes.length; i++) {
      const child = childNodes[i];
      const result = findTextNode(child);
      if (result) {
        return result;
      }
    }
    return false;
  } else {
    const place = node.textContent.search('R');
    if (!node.tagName && place!==-1) {
      return node;
    }
    return false;
  }
}

Working fiddle here: http://jsfiddle.net/1x6knn37/

Leave a comment