Menu

#101 unable to set attribute after insert an element on innertext

closed
None
2019-04-19
2012-03-16
Ian
No

I ripped my hair out trying to figure this out. Originally I thought it was a reference problem, but not at all, it's actually because I was inserting an element on innertext.

    // make sure caption exists
    if ( ! $table->find("caption", 0))
    {
        $table->innertext = "<caption><!-- insert caption --></caption>".$table->innertext; // causes problems setting attributes after this point

// $table->first_child()->outertext = "".$table->first_child()->outertext; // workaround
}

    foreach ($table->find('tr') as $tr)
    {
        $tr->bgcolor = NULL;
        remove_classes($tr, array('tablecolor', 'widget'));
    }

I found the best workaround was to get the first child and insert on the outertext of that element, as described in the API.

However, my intuition told me that it wouldn't be a problem to insert an element on innertext and I believe this should at least be documented.

Discussion

  • LogMANOriginal

    LogMANOriginal - 2019-04-19
    • status: open --> closed
    • assigned_to: LogMANOriginal
    • discussion: enabled --> disabled
     
  • LogMANOriginal

    LogMANOriginal - 2019-04-19

    The parser currently doesn't support adding elements to the tree. Closing in favor of [feature-requests:#7]. Please continue discussion on that ticket.

     

    Related

    Feature Requests: #7

MongoDB Logo MongoDB