0

I made insert html in table list. Correctly that can run. But, It dose not apply css. I tried document.ready or windows.load that can't apply css.

I used Bootstrap and Jquery. This code can't apply css from button.

function makeTable(dataList, elId) {
    var id = document.getElementById(elId);

   // Make Button
   var frame = `<td>
                  <button type="button" class="btn btn-warning waves-effect" onclick="alert('{0}')">
                     <i class="material-icons">info_outline</i>
                  </button>
                  <button type="button" class="btn btn-danger waves-effect" onclick="alert('{0}')" data-type="cancel">
                     <i class="material-icons">delete</i>
                  </button>
               </td>`;

    dataList.forEach( data => {
      var tr = document.createElement('tr');
      for (key in data) {
         switch (key) {
            case 'edit':
               tr.appendChild(new DOMParser().parseFromString(frame.format(data[key]), "text/xml").firstChild);
               break;
            default:
               var td = document.createElement('td');
               td.appendChild(document.createTextNode(data[key]));
               tr.appendChild(td);
         }
         
      }
      id.querySelector("tbody").appendChild(tr);
    });
}

It result under picture. enter image description here

Icon and style was not to apply it.

4
  • Can you give us any example page on the CodePen or something? Commented Sep 5, 2020 at 15:01
  • I did test other attribute. '.appendChild' It was run. Commented Sep 5, 2020 at 15:27
  • I don't understand what "cannot apply CSS" means. CSS applies to all page contents, regardless of whether they are added later on or have been there all the time. Please create a minimum, reproducable example ideally in a runnable code snippet here. Commented Sep 5, 2020 at 15:30
  • Also, on your screenshot you seem to have messed up markup in the Edit column. Commented Sep 5, 2020 at 15:31

1 Answer 1

0

You do not have this css classes on your page. It doesn't depend on js in any way. Perhaps iframe is used so css is not available.

Sign up to request clarification or add additional context in comments.

4 Comments

I have css file. This page do not use iframe. When this buttons define in the code. So, it was correctly running. But, Insert html, it was can't run
JS cannot interfere with the rendering of css in any way. You can make sure like this: var frame = ` <style> .material-icons{ color:red;} </style> <td> ....
Maybe i think "new DOMParser().parseFromString" is to wired.
Please, create example in codepen.io, i will check code .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.