No Work nextElementSibling & children on JS

Viewed 30

I want use nextElementSibling & children on vanila JS, a works on Inspect Element Console and no work on my function from JS.

Sorry for Grammar Mistakes

JavaScript Code

  /**
 * PHP-like print_r() & var_dump() equivalent for JavaScript Object
 *
 * @author Faisalman <movedpixel@gmail.com>
 * @license http://www.opensource.org/licenses/mit-license.php
 * @link http://gist.github.com/879208
 */
 var print_r = function(obj,t){

  // define tab spacing
  var tab = t || '';

  // check if it's array
  var isArr = Object.prototype.toString.call(obj) === '[object Array]' ? true : false;

  // use {} for object, [] for array
  var str = isArr ? ('Array\n' + tab + '[\n') : ('Object\n' + tab + '{\n');

  // walk through it's properties
  for(var prop in obj){
      if (obj.hasOwnProperty(prop)) {
          var val1 = obj[prop];
          var val2 = '';
          var type = Object.prototype.toString.call(val1);
          switch(type){
    
              // recursive if object/array
              case '[object Array]':
              case '[object Object]':
                  val2 = print_r(val1, (tab + '\t'));
                  break;
        
              case '[object String]':
                  val2 = '\'' + val1 + '\'';
                  break;
        
              default:
                  val2 = val1;
          }
          str += tab + '\t' + prop + ' => ' + val2 + ',\n';
      }
  }

  // remove extra comma for last property
  str = str.substring(0, str.length-2) + '\n' + tab;

  return isArr ? (str + ']') : (str + '}');
};
var var_dump = print_r; // equivalent function

function build_editbox(id) {
  testid = "#" + id
  CKEDITOR.ClassicEditor.create(document.querySelector(testid), {
    // https://ckeditor.com/docs/ckeditor5/latest/features/toolbar/toolbar.html#extended-toolbar-configuration-format
    toolbar: {
      items: [
        "bold",
        "italic",
        "strikethrough",
        "underline",
        "numberedList",
        "todoList",
        "fontSize",
        "fontColor",
        "uploadImage",
      ],
      /*items: [
            'bold', 'italic', 'strikethrough', 'underline', 
            'numberedList', 'todoList', '|',
            'fontSize', 'fontFamily', 'fontColor', '|',
            'link', 'uploadImage', '|',
        ],*/
      shouldNotGroupWhenFull: true,
    },
    placeholder: "Write Your Note",
    fontFamily: {
      options: [
        "default",
        "Arial, Helvetica, sans-serif",
        "Courier New, Courier, monospace",
        "Georgia, serif",
        "Lucida Sans Unicode, Lucida Grande, sans-serif",
        "Tahoma, Geneva, sans-serif",
        "Times New Roman, Times, serif",
        "Trebuchet MS, Helvetica, sans-serif",
        "Verdana, Geneva, sans-serif",
      ],
      supportAllValues: true,
    },
    fontSize: {
      options: [10, 12, 14, "default", 18, 20, 22, 24, 26],
      supportAllValues: true,
    },
    link: {
      decorators: {
        addTargetToExternalLinks: true,
        defaultProtocol: "https://",
      },
    },
    removePlugins: [
      "ExportPdf",
      "ExportWord",
      "CKBox",
      "CKFinder",
      "EasyImage",
      "RealTimeCollaborativeComments",
      "RealTimeCollaborativeTrackChanges",
      "RealTimeCollaborativeRevisionHistory",
      "PresenceList",
      "Comments",
      "TrackChanges",
      "TrackChangesData",
      "RevisionHistory",
      "Pagination",
      "WProofreader",
      "MathType",
    ],
  });
  //setTimeout(function(){    $(".ck-list-styles-dropdown").children().children()[1].remove()}, 900)
}


function restore_editbox(id, msg){
  //n2 = "text-editor" + id
  n2 = id 
  build_editbox(n2);
  n3 = "#" + n2

  notebox = document.getElementById(n2);

  console.warn(id, "||", n2, "|", n3)
  console.warn("%c" + msg, "color: purple; font-size: 32px;")
  if (!notebox) {
    console.error("ERROR");
    return;
  }


  d = notebox.nextElementSibling;
  //var_dump(d)
  console.log("%c" + d, "color: pink;font-size: 15px;");
  console.log("%c" + d, "color: brown;font-size: 15px;");
  xw = n3;
  //var_dump(xw);
  d.children[2].children[0].children[0].innerHTML = msg;

}

No Work restore_editbox(id_note, msg)

etc: id_note: "text-editor1" & msg: "Example Text"

Good Day

Thanks for Help
0 Answers
Related