0

I tried to add some label on Sharepoint 2013 forms with jquery prepend. I write a code for testing purpose, add a row with text 'Label1' before column name 'Project'. It doesn't work, 'Label1' is not showing up. See code below.

<script type="text/javascript" src="mysite/SiteAssets/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    $(doucument).ready(function(){
       $('nobr:contains("Project")').closest('tr').prepend("<tr><td colspan='2'>label1</td></tr>");
    });
</script>
3
  • What is the error in your browser's console? Can you please check and add the error you are getting in your question? Commented Sep 6, 2019 at 12:05
  • no error in browser's console.
    – JJL
    Commented Sep 6, 2019 at 12:16
  • It works after refresh a couple of time. But the 'label1' is showing just in front of 'Project', not in a new row even though I add <br>. How to fix it?
    – JJL
    Commented Sep 6, 2019 at 12:36

1 Answer 1

0

You should use the below code.

<script type="text/javascript" src="mysite/SiteAssets/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    $(doucument).ready(function(){
       $('nobr:contains("Project")').closest('tr').before("<tr><td colspan='2'>label1</td></tr>");
    });
</script>

Append or prepending will put data INSIDE the caller elements. While After and before will create sibling elements. This might help you understand.

1
  • Thank you! It works.
    – JJL
    Commented Sep 6, 2019 at 12:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.