Content editor web part issue not rendering HTML











up vote
2
down vote

favorite












I'm having an issue w/ a Content Editor Web Part. I would like to add an HTML table that gives users the ability to add and remove rows from a table. How should I add the following code to the CEW? Does it support this type of thing?



$('.AddNew').click(function(){
var row = $(this).closest('tr').clone();
row.find('input').val('');
$(this).closest('tr').after(row);
$('input[type="button"]', row).removeClass('AddNew')
.addClass('RemoveRow').val('Remove item');
});

$('table').on('click', '.RemoveRow', function(){
$(this).closest('tr').remove();
});


And the HTML:



<table>
<tr><td>Item Type</td><td>Item</td><td>Add/Remove Item</td></tr>
<tr><td><input type='text' value='Fruit >'></td>
<td><input type='text' value='Apple'></td>
<td><input type='button' class='AddNew' value='Add new item'></td></tr>
</table>


Thanks.










share|improve this question


























    up vote
    2
    down vote

    favorite












    I'm having an issue w/ a Content Editor Web Part. I would like to add an HTML table that gives users the ability to add and remove rows from a table. How should I add the following code to the CEW? Does it support this type of thing?



    $('.AddNew').click(function(){
    var row = $(this).closest('tr').clone();
    row.find('input').val('');
    $(this).closest('tr').after(row);
    $('input[type="button"]', row).removeClass('AddNew')
    .addClass('RemoveRow').val('Remove item');
    });

    $('table').on('click', '.RemoveRow', function(){
    $(this).closest('tr').remove();
    });


    And the HTML:



    <table>
    <tr><td>Item Type</td><td>Item</td><td>Add/Remove Item</td></tr>
    <tr><td><input type='text' value='Fruit >'></td>
    <td><input type='text' value='Apple'></td>
    <td><input type='button' class='AddNew' value='Add new item'></td></tr>
    </table>


    Thanks.










    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'm having an issue w/ a Content Editor Web Part. I would like to add an HTML table that gives users the ability to add and remove rows from a table. How should I add the following code to the CEW? Does it support this type of thing?



      $('.AddNew').click(function(){
      var row = $(this).closest('tr').clone();
      row.find('input').val('');
      $(this).closest('tr').after(row);
      $('input[type="button"]', row).removeClass('AddNew')
      .addClass('RemoveRow').val('Remove item');
      });

      $('table').on('click', '.RemoveRow', function(){
      $(this).closest('tr').remove();
      });


      And the HTML:



      <table>
      <tr><td>Item Type</td><td>Item</td><td>Add/Remove Item</td></tr>
      <tr><td><input type='text' value='Fruit >'></td>
      <td><input type='text' value='Apple'></td>
      <td><input type='button' class='AddNew' value='Add new item'></td></tr>
      </table>


      Thanks.










      share|improve this question













      I'm having an issue w/ a Content Editor Web Part. I would like to add an HTML table that gives users the ability to add and remove rows from a table. How should I add the following code to the CEW? Does it support this type of thing?



      $('.AddNew').click(function(){
      var row = $(this).closest('tr').clone();
      row.find('input').val('');
      $(this).closest('tr').after(row);
      $('input[type="button"]', row).removeClass('AddNew')
      .addClass('RemoveRow').val('Remove item');
      });

      $('table').on('click', '.RemoveRow', function(){
      $(this).closest('tr').remove();
      });


      And the HTML:



      <table>
      <tr><td>Item Type</td><td>Item</td><td>Add/Remove Item</td></tr>
      <tr><td><input type='text' value='Fruit >'></td>
      <td><input type='text' value='Apple'></td>
      <td><input type='button' class='AddNew' value='Add new item'></td></tr>
      </table>


      Thanks.







      content-editor-web-part






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 5 at 12:38









      Martin Muldoon

      299111




      299111






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Content Editor web part is normally used to display the contents on the screen. In your case, you have HTML and jQuery code. So you have to format your code in proper HTML format and then paste it in content editor webpart. For example,



          Also you have to add $(document).ready(); into your code. Your final code should be



          <html>
          <head>
          <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
          <script>
          $(document).ready(function() {
          $('.AddNew').click(function() {
          var row = $(this)
          .closest('tr')
          .clone();
          row.find('input').val('');
          $(this)
          .closest('tr')
          .after(row);
          $('input[type="button"]', row)
          .removeClass('AddNew')
          .addClass('RemoveRow')
          .val('Remove item');
          });

          $('table').on('click', '.RemoveRow', function() {
          $(this)
          .closest('tr')
          .remove();
          });
          });
          </script>
          </head>
          <body>
          <table>
          <tr>
          <td>Item Type</td>
          <td>Item</td>
          <td>Add/Remove Item</td>
          </tr>
          <tr>
          <td><input type="text" value="Fruit >" /></td>
          <td><input type="text" value="Apple" /></td>
          <td><input type="button" class="AddNew" value="Add new item" /></td>
          </tr>
          </table>
          </body>
          </html>


          You can read more about content editor webpart here



          Alternate option:



          You can create HTML file, paste the code in answer into the HTML file, upload the HTML file to document library or site asset.



          Copy the path of the HTML file.



          Edit Content Editor webpart and paste the link over there



          enter image description here



          Click on OK and save the page. This will definitely work.



          Let me know if this helped.






          share|improve this answer



















          • 1




            Thanks for this! I've added code.jquery.com/jquery-3.3.1.js to src="pathtojQuery" yet the CEW is still not rendering the HTML, but rather just showing the code as I pasted it. Any further thoughts?
            – Martin Muldoon
            Dec 5 at 12:53










          • Then what you can do is, you can create a HTML file and paste the code into that. And then upload the html file to Document library or SIte Asset library. And copy the path of the HTML file and edit the content editor webpart and in the link section enter the path of the html file there and save the page. Let me add this portion also to the answer.
            – Aakash Maurya
            Dec 5 at 13:08






          • 1




            I'll give that a shot. Thanks!
            – Martin Muldoon
            Dec 5 at 13:24










          • You also have to add $(document).ready() to your code. I tried your code and it worked only when I added $(document).ready(). I have updated the final code to the answer
            – Aakash Maurya
            Dec 5 at 13:26






          • 1




            Ha! Worked perfectly. Thank You!!
            – Martin Muldoon
            Dec 5 at 13:39











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "232"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsharepoint.stackexchange.com%2fquestions%2f253768%2fcontent-editor-web-part-issue-not-rendering-html%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote



          accepted










          Content Editor web part is normally used to display the contents on the screen. In your case, you have HTML and jQuery code. So you have to format your code in proper HTML format and then paste it in content editor webpart. For example,



          Also you have to add $(document).ready(); into your code. Your final code should be



          <html>
          <head>
          <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
          <script>
          $(document).ready(function() {
          $('.AddNew').click(function() {
          var row = $(this)
          .closest('tr')
          .clone();
          row.find('input').val('');
          $(this)
          .closest('tr')
          .after(row);
          $('input[type="button"]', row)
          .removeClass('AddNew')
          .addClass('RemoveRow')
          .val('Remove item');
          });

          $('table').on('click', '.RemoveRow', function() {
          $(this)
          .closest('tr')
          .remove();
          });
          });
          </script>
          </head>
          <body>
          <table>
          <tr>
          <td>Item Type</td>
          <td>Item</td>
          <td>Add/Remove Item</td>
          </tr>
          <tr>
          <td><input type="text" value="Fruit >" /></td>
          <td><input type="text" value="Apple" /></td>
          <td><input type="button" class="AddNew" value="Add new item" /></td>
          </tr>
          </table>
          </body>
          </html>


          You can read more about content editor webpart here



          Alternate option:



          You can create HTML file, paste the code in answer into the HTML file, upload the HTML file to document library or site asset.



          Copy the path of the HTML file.



          Edit Content Editor webpart and paste the link over there



          enter image description here



          Click on OK and save the page. This will definitely work.



          Let me know if this helped.






          share|improve this answer



















          • 1




            Thanks for this! I've added code.jquery.com/jquery-3.3.1.js to src="pathtojQuery" yet the CEW is still not rendering the HTML, but rather just showing the code as I pasted it. Any further thoughts?
            – Martin Muldoon
            Dec 5 at 12:53










          • Then what you can do is, you can create a HTML file and paste the code into that. And then upload the html file to Document library or SIte Asset library. And copy the path of the HTML file and edit the content editor webpart and in the link section enter the path of the html file there and save the page. Let me add this portion also to the answer.
            – Aakash Maurya
            Dec 5 at 13:08






          • 1




            I'll give that a shot. Thanks!
            – Martin Muldoon
            Dec 5 at 13:24










          • You also have to add $(document).ready() to your code. I tried your code and it worked only when I added $(document).ready(). I have updated the final code to the answer
            – Aakash Maurya
            Dec 5 at 13:26






          • 1




            Ha! Worked perfectly. Thank You!!
            – Martin Muldoon
            Dec 5 at 13:39















          up vote
          4
          down vote



          accepted










          Content Editor web part is normally used to display the contents on the screen. In your case, you have HTML and jQuery code. So you have to format your code in proper HTML format and then paste it in content editor webpart. For example,



          Also you have to add $(document).ready(); into your code. Your final code should be



          <html>
          <head>
          <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
          <script>
          $(document).ready(function() {
          $('.AddNew').click(function() {
          var row = $(this)
          .closest('tr')
          .clone();
          row.find('input').val('');
          $(this)
          .closest('tr')
          .after(row);
          $('input[type="button"]', row)
          .removeClass('AddNew')
          .addClass('RemoveRow')
          .val('Remove item');
          });

          $('table').on('click', '.RemoveRow', function() {
          $(this)
          .closest('tr')
          .remove();
          });
          });
          </script>
          </head>
          <body>
          <table>
          <tr>
          <td>Item Type</td>
          <td>Item</td>
          <td>Add/Remove Item</td>
          </tr>
          <tr>
          <td><input type="text" value="Fruit >" /></td>
          <td><input type="text" value="Apple" /></td>
          <td><input type="button" class="AddNew" value="Add new item" /></td>
          </tr>
          </table>
          </body>
          </html>


          You can read more about content editor webpart here



          Alternate option:



          You can create HTML file, paste the code in answer into the HTML file, upload the HTML file to document library or site asset.



          Copy the path of the HTML file.



          Edit Content Editor webpart and paste the link over there



          enter image description here



          Click on OK and save the page. This will definitely work.



          Let me know if this helped.






          share|improve this answer



















          • 1




            Thanks for this! I've added code.jquery.com/jquery-3.3.1.js to src="pathtojQuery" yet the CEW is still not rendering the HTML, but rather just showing the code as I pasted it. Any further thoughts?
            – Martin Muldoon
            Dec 5 at 12:53










          • Then what you can do is, you can create a HTML file and paste the code into that. And then upload the html file to Document library or SIte Asset library. And copy the path of the HTML file and edit the content editor webpart and in the link section enter the path of the html file there and save the page. Let me add this portion also to the answer.
            – Aakash Maurya
            Dec 5 at 13:08






          • 1




            I'll give that a shot. Thanks!
            – Martin Muldoon
            Dec 5 at 13:24










          • You also have to add $(document).ready() to your code. I tried your code and it worked only when I added $(document).ready(). I have updated the final code to the answer
            – Aakash Maurya
            Dec 5 at 13:26






          • 1




            Ha! Worked perfectly. Thank You!!
            – Martin Muldoon
            Dec 5 at 13:39













          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          Content Editor web part is normally used to display the contents on the screen. In your case, you have HTML and jQuery code. So you have to format your code in proper HTML format and then paste it in content editor webpart. For example,



          Also you have to add $(document).ready(); into your code. Your final code should be



          <html>
          <head>
          <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
          <script>
          $(document).ready(function() {
          $('.AddNew').click(function() {
          var row = $(this)
          .closest('tr')
          .clone();
          row.find('input').val('');
          $(this)
          .closest('tr')
          .after(row);
          $('input[type="button"]', row)
          .removeClass('AddNew')
          .addClass('RemoveRow')
          .val('Remove item');
          });

          $('table').on('click', '.RemoveRow', function() {
          $(this)
          .closest('tr')
          .remove();
          });
          });
          </script>
          </head>
          <body>
          <table>
          <tr>
          <td>Item Type</td>
          <td>Item</td>
          <td>Add/Remove Item</td>
          </tr>
          <tr>
          <td><input type="text" value="Fruit >" /></td>
          <td><input type="text" value="Apple" /></td>
          <td><input type="button" class="AddNew" value="Add new item" /></td>
          </tr>
          </table>
          </body>
          </html>


          You can read more about content editor webpart here



          Alternate option:



          You can create HTML file, paste the code in answer into the HTML file, upload the HTML file to document library or site asset.



          Copy the path of the HTML file.



          Edit Content Editor webpart and paste the link over there



          enter image description here



          Click on OK and save the page. This will definitely work.



          Let me know if this helped.






          share|improve this answer














          Content Editor web part is normally used to display the contents on the screen. In your case, you have HTML and jQuery code. So you have to format your code in proper HTML format and then paste it in content editor webpart. For example,



          Also you have to add $(document).ready(); into your code. Your final code should be



          <html>
          <head>
          <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
          <script>
          $(document).ready(function() {
          $('.AddNew').click(function() {
          var row = $(this)
          .closest('tr')
          .clone();
          row.find('input').val('');
          $(this)
          .closest('tr')
          .after(row);
          $('input[type="button"]', row)
          .removeClass('AddNew')
          .addClass('RemoveRow')
          .val('Remove item');
          });

          $('table').on('click', '.RemoveRow', function() {
          $(this)
          .closest('tr')
          .remove();
          });
          });
          </script>
          </head>
          <body>
          <table>
          <tr>
          <td>Item Type</td>
          <td>Item</td>
          <td>Add/Remove Item</td>
          </tr>
          <tr>
          <td><input type="text" value="Fruit >" /></td>
          <td><input type="text" value="Apple" /></td>
          <td><input type="button" class="AddNew" value="Add new item" /></td>
          </tr>
          </table>
          </body>
          </html>


          You can read more about content editor webpart here



          Alternate option:



          You can create HTML file, paste the code in answer into the HTML file, upload the HTML file to document library or site asset.



          Copy the path of the HTML file.



          Edit Content Editor webpart and paste the link over there



          enter image description here



          Click on OK and save the page. This will definitely work.



          Let me know if this helped.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 5 at 13:24

























          answered Dec 5 at 12:46









          Aakash Maurya

          7,05831649




          7,05831649








          • 1




            Thanks for this! I've added code.jquery.com/jquery-3.3.1.js to src="pathtojQuery" yet the CEW is still not rendering the HTML, but rather just showing the code as I pasted it. Any further thoughts?
            – Martin Muldoon
            Dec 5 at 12:53










          • Then what you can do is, you can create a HTML file and paste the code into that. And then upload the html file to Document library or SIte Asset library. And copy the path of the HTML file and edit the content editor webpart and in the link section enter the path of the html file there and save the page. Let me add this portion also to the answer.
            – Aakash Maurya
            Dec 5 at 13:08






          • 1




            I'll give that a shot. Thanks!
            – Martin Muldoon
            Dec 5 at 13:24










          • You also have to add $(document).ready() to your code. I tried your code and it worked only when I added $(document).ready(). I have updated the final code to the answer
            – Aakash Maurya
            Dec 5 at 13:26






          • 1




            Ha! Worked perfectly. Thank You!!
            – Martin Muldoon
            Dec 5 at 13:39














          • 1




            Thanks for this! I've added code.jquery.com/jquery-3.3.1.js to src="pathtojQuery" yet the CEW is still not rendering the HTML, but rather just showing the code as I pasted it. Any further thoughts?
            – Martin Muldoon
            Dec 5 at 12:53










          • Then what you can do is, you can create a HTML file and paste the code into that. And then upload the html file to Document library or SIte Asset library. And copy the path of the HTML file and edit the content editor webpart and in the link section enter the path of the html file there and save the page. Let me add this portion also to the answer.
            – Aakash Maurya
            Dec 5 at 13:08






          • 1




            I'll give that a shot. Thanks!
            – Martin Muldoon
            Dec 5 at 13:24










          • You also have to add $(document).ready() to your code. I tried your code and it worked only when I added $(document).ready(). I have updated the final code to the answer
            – Aakash Maurya
            Dec 5 at 13:26






          • 1




            Ha! Worked perfectly. Thank You!!
            – Martin Muldoon
            Dec 5 at 13:39








          1




          1




          Thanks for this! I've added code.jquery.com/jquery-3.3.1.js to src="pathtojQuery" yet the CEW is still not rendering the HTML, but rather just showing the code as I pasted it. Any further thoughts?
          – Martin Muldoon
          Dec 5 at 12:53




          Thanks for this! I've added code.jquery.com/jquery-3.3.1.js to src="pathtojQuery" yet the CEW is still not rendering the HTML, but rather just showing the code as I pasted it. Any further thoughts?
          – Martin Muldoon
          Dec 5 at 12:53












          Then what you can do is, you can create a HTML file and paste the code into that. And then upload the html file to Document library or SIte Asset library. And copy the path of the HTML file and edit the content editor webpart and in the link section enter the path of the html file there and save the page. Let me add this portion also to the answer.
          – Aakash Maurya
          Dec 5 at 13:08




          Then what you can do is, you can create a HTML file and paste the code into that. And then upload the html file to Document library or SIte Asset library. And copy the path of the HTML file and edit the content editor webpart and in the link section enter the path of the html file there and save the page. Let me add this portion also to the answer.
          – Aakash Maurya
          Dec 5 at 13:08




          1




          1




          I'll give that a shot. Thanks!
          – Martin Muldoon
          Dec 5 at 13:24




          I'll give that a shot. Thanks!
          – Martin Muldoon
          Dec 5 at 13:24












          You also have to add $(document).ready() to your code. I tried your code and it worked only when I added $(document).ready(). I have updated the final code to the answer
          – Aakash Maurya
          Dec 5 at 13:26




          You also have to add $(document).ready() to your code. I tried your code and it worked only when I added $(document).ready(). I have updated the final code to the answer
          – Aakash Maurya
          Dec 5 at 13:26




          1




          1




          Ha! Worked perfectly. Thank You!!
          – Martin Muldoon
          Dec 5 at 13:39




          Ha! Worked perfectly. Thank You!!
          – Martin Muldoon
          Dec 5 at 13:39


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to SharePoint Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsharepoint.stackexchange.com%2fquestions%2f253768%2fcontent-editor-web-part-issue-not-rendering-html%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Plaza Victoria

          In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

          How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...